From: 7stud -- Date: 2011-05-14T02:50:13+09:00 Subject: Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails wrote in post #998460: > > I have only one question: I put a space between the & and the method > following it; the code broke. Is the construct you used documented on- > line somewhere? I've peeked at lambda documentation so I've got the > drift but I haven't used it in any of my code so far. > Your bible, "The Well-Grounded Rubyist" uses the &:meth_name construct a lot, and David Black says that the '&' in '&:meth_name' does two things: 1) It calls the specified object's to_proc() method. And Symbol#to_proc is defined like this: class Symbol def to_proc proc{|obj, *args| obj.send(self, *args)} #self=:meth_name end end That just creates a function that takes an object as an argument and sends() the :meth_name to the object, i.e. the function calls the :meth_name method on the object. 2) The '&' tells ruby to convert the Proc to a block. -- Posted via http://www.ruby-forum.com/.