From: RichardOnRails Date: 2011-05-24T11:25:27+09:00 Subject: Re: Scope problem (?) in implementing Design Patterns in Ruby On May 13, 1:50 pm, 7stud -- wrote: > 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 viahttp://www.ruby-forum.com/. Hi 7stud, I just your the response you posted a week of two ago, for which I am grateful > Your bible, "The Well-Grounded Rubyist" uses the &:meth_name construct a > lot, and David Black says that... I had looked at the indices of several books for a reference to the prefix &, to no avail. So I abandoned that idea and thus never checked Black's book. Thanks to your note, I see that Black has indexed two dense sections related to the prefixed &, so I've got them on my To-Do list for study. Thanks again for taking the trouble to directing me to Black's coverage. Best wishes, Richard