Rubyist Hotlinks
角谷さんの好きなメソッド嫌いなメソッドを読んで。
Object#extend
Module#includeはクラスへのMixinで、Object#extendはインスタンスへのMixin。
module Rubycolify def rubyco p self.to_s end end s = "Hello" s.extend(Rubycolify) s.rubyco #=> "Hello" t = "Bad" t.rubyco #=> undefined method `rubyco'
Enumerable#collectとEnumerable#map
p (0..9).collect {|e| e * 2} #=> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] p (0..9).map {|e| e * 2} #=> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Enumerable#select
p (0..9).select {|e| e % 2 == 0 } #=> [0, 2, 4, 6, 8]
Module#const_get
p Math.const_get("PI") #=> 3.14159265358979
(しまった、例がri Module#const_getと(ほぼ)同じになった)