Gian Holland
5/30/2007 5:57:00 PM
Thanks so much
On 5/29/07, Stefano Crocco <stefano.crocco@alice.it> wrote:
> Alle martedì 29 maggio 2007, Gian Holland ha scritto:
> > Hi I have a beginner question
> >
> > What does the => operator do?
> >
> > here is the example code from the book
> >
> > class Product < ActiveRecord::Base
> > has_many :orders, :through *=>* :line_items
> > #...
>
> => is not an operator, its simply the syntax used to create hashes:
>
> h = {:a => 1, :b=>2}
>
> creates an hash with keys :a and :b, corresponding to values 1 and 2
> respectively. When you need to pass an hash as the last argument of a method,
> ruby allows you to omit the braces, so your call to has many means:
>
> has_many( :orders, {:through => :line_items} )
>
> In other words, you're passing two arguments to the method has_many: the first
> is the Symbol :orders; the second is a Hash with one key (:through) and one
> value (:line_items)
>
> Stefano
>
>
>
>