From: Li Chen Date: 2009-06-03T12:09:46+09:00 Subject: Re: Do I need self in this method definition matt neuburg wrote: > You do if you really want a class method - that is, if you want to be > able to call this thing by saying Hash.my_each(hash1, hash2). > > The alternative is to make an instance method. Then you could call it by > saying hash1.my_each(hash2). In that case, you would not use "self" in > the def. m. Thank you so much. Here is my implement of an instance method. But I cannot explain very clear why I can #each directly without a receiver. Li class Hash def my_each(hash2={}) each do |k,v| if hash2.has_key?(k) print k,"\t",v,"\t", hash2[k],"\n" else print k,"\t",v,"\n" end end end end -- Posted via http://www.ruby-forum.com/.