Hi --

On Tue, 25 Mar 2008, Ruby Freak wrote:

> Hi and thanks in advance for your help.
> I have been pounding every Ruby and Rails book I can find, desperately
> attempting to move beyond newbie status.My latest foray has taken me
> into the native 2.0.2 Rails::Info module. I am reading what I think is
> native ruby code but I can't seem to figure out what is being passed
> to map and find. Could someone please explain (name, ) in the
> following code?
>
> Thanks again.
>
> module Rails
>  module Info
>    mattr_accessor :properties
>
>    class << (@@properties = [])
>      def names
>        map {|(name, )| name}
>      end
>
>      def value_for(property_name)
>        find {|(name, )| name == property_name}.last rescue nil
>      end
>    end

find and map are not being passed any arguments; rather, they're being
given code blocks, and those blocks are being passed arguments.
(name,) is block parameter syntax for grabbing one element of an array
and putting it in name.


David

-- 
Upcoming Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS   April 14-17          New York City
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
   CORE RAILS             June 24-27           London (Skills Matter)
See http://www.rubypal.com for more info!