In a method declaration, *a means make an array of all the values passed to
the function. So when the method to_json is called with to_json(1,2,3 true),
a would equal [1,2,3,true]

Using *a when calling a method, the variable is "exploded" into separate
arguments for the method call. For example:

a = [1,2,3]
to_json(*a) would be the same as calling to_json(1,2,3)

Hope that helps,
Bradly



On Sat, Feb 26, 2011 at 10:04 AM, misham <[email protected]> wrote:

> I'm looking at the code at http://flori.github.com/json/  and the
> example given is:
>
> class Range
>  def to_json(*a)
>    {
>      'json_class'   => self.class.name,
>      'data'         => [ first, last, exclude_end? ]
>    }.to_json(*a)
>  end
>
>  def self.json_create(o)
>    new(*o['data'])
>  end
> end
>
>
> What does *a mean in the to_json function parameter list?
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to