Twitter
- @jy788 이건 바람이 아니라 공포군요. 제주는 장마 아닌 장마에 태풍 아닌 태풍이군요. in reply to jy788 13 hrs ago
- @yorena 한국 야후도 비번 모르니 장난 아니던데요. 플리커 때문에 결국 다른 아이디로 가입했어요. in reply to yorena 13 hrs ago
- 베란다 앞 텃밭에 깡패 직박구리 출현. 얼렁 출근해야겠다. http://twitpic.com/17zwyi 20 hrs ago
- More updates...
Posting tweet...
Powered by Twitter Tools
카테고리
- Java (13)
- Ruby (4)
- Software & Developer (54)
- 그들의 이야기 (12)
- 깨달음으로 가는 길 (47)
- 러블 이야기 (8)
- 시골생황 (8)
-
최근 작성글
-
최근 덧글
- Alameida on 나는 오늘도 배움을 멈출 수 없다.
- sebastian on Daum 제주에서 일해야하는 3가지 이유
- 따지크 on Big Think – 창의적인 전략의 발굴과 실천방법
Ruby를 배우는 Java 개발자가 알아야 할 10가지 part 3
Java 개발자가 알아야 할 10가지
Item #4 믹스인(Mix-In)을 사용한 클래스 확장
루비는 인터페이스가 없지만 모듈로 정의된 믹스인이 있다.
모듈이란..
- 모듈의 메소드는 클래스의 메소드가 된다.
믹스인 재사용
module LessComparable def >(other) other < self end # Other methods defined in terms of less than: # <=, >=, == end class Pair include LessComparable attr_accessor :first, :second # ... def <(other) (first < other.first) || (first == other.first && second < other.second) end endItem #3 구문(closure) 감싸기
file_contents = open(file_name) { |f| f.read }widget.on_button_press { puts "Got Button Press" }Item #2 ri 는 당신의 친구, irb 도 당신의 친구
루비 정보(Ruby Information). 표준 루비 객체에 대한 메뉴얼 페이지(Man pages)
$ ri Array ---------------------------------------------------------- Module: Array Arrays are ordered, integer-indexed collections of any object. Array indexing starts at 0, as in C or Java. A negative index is assumed to be relative to the end of the array---that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on. ------------------------------------------------------------------------ Includes: --------- Enumerable(all?, any?, collect, detect, each_with_index, entries, find, find_all, grep, include?, inject, map, max, member?, min, partition, reject, select, sort, sort_by, to_a, zip) Class methods: -------------- [], new Instance methods: ----------------- &, *, +, -, <<, <=>, ==, [], []=, assoc, at, clear, collect, collect!, compact, compact!, concat, delete, delete_at, delete_if, each, each_index, empty?, eql?, fetch, fill, first, flatten, flatten!, frozen?, hash, include?, index, indexes, indices, insert, inspect, join, last, length, map, map!, nitems, pack, pop, push, rassoc, reject, reject!, replace, reverse, reverse!, reverse_each, rindex, select, shift, slice, slice!, sort, sort!, to_a, to_ary, to_s, transpose, uniq, uniq!, unshift, values_at, zip, | $ ri Array#last ------------------------------------------------------------- Array#last array.last => obj or nil array.last(n) => an_array ------------------------------------------------------------------------ Returns the last element(s) of _self_. If the array is empty, the first form returns +nil+. [ "w", "x", "y", "z" ].last #=> "z"루비 콘솔(Interactive Ruby). 콘솔 기반의 루비 실행기(Ruby interpreter)
$ irb --simple-prompt >> 1 + 2 => 3 >> Proc.instance_methods(false) => ["[]", "==", "dup", "call", "binding", "to_s", "clone", "to_proc", "arity"]Item #1 이제 길고 긴 코드 작성은 그만!
동료 개발자 왈...
예제 코드
* Copland (Hivemind의 Ruby 버젼) VS Needle Libraries
* Rake (Make의 Ruby 버젼)