Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4504
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Scope problem (?) in implementing Design Patterns in Ruby |
| Date | 2011-05-13 12:50 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <4bc0d1972260442c6d44caba7e6eefaf@ruby-forum.com> (permalink) |
| References | (3 earlier) <9307dd9ab066746e74f5cbc1f8d02bbf@ruby-forum.com> <BANLkTin3iMtQZ7MiAfhG0Eg=XwnrfgbwGA@mail.gmail.com> <1a2fe490-3ad8-4c68-b1c2-2db31012a1a3@f31g2000pri.googlegroups.com> <C32E785734DD47739FFE9B46581FD36C@wit.io> <5e7178b8-0f8c-4039-b43c-be0c350c0b58@dn9g2000vbb.googlegroups.com> |
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/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-11 10:15 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-11 12:52 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-11 12:53 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-11 13:37 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-11 18:07 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-11 17:30 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 14:28 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 15:23 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-11 15:26 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 15:45 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 15:34 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-11 15:48 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-12 08:59 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-12 20:56 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 21:11 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-12 21:18 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-13 00:28 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-13 09:46 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-13 10:55 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-13 12:50 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby Steve Klabnik <steve@steveklabnik.com> - 2011-05-13 13:14 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-23 19:24 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-24 20:33 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-25 17:30 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails <RichardDummyMailbox58407@USComputerGurus.com> - 2011-05-27 22:08 -0700
Re: Scope problem (?) in implementing Design Patterns in Ruby 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 21:20 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby David Jacobs <developer@wit.io> - 2011-05-12 21:26 -0500
Re: Scope problem (?) in implementing Design Patterns in Ruby Ryan Davis <ryand-ruby@zenspider.com> - 2011-05-13 12:29 -0500
csiph-web