I was just going through the section15.6 of agile web development PDF but somehow couldn't understand how actually the & parameter works .

0 views
Skip to first unread message

Jhonny

unread,
Sep 5, 2007, 12:40:43 AM9/5/07
to Rails India
Hi,

I was just going through the section15.6 of agile web development PDF
but somehow couldn't understand how actually the & parameter works .

Check 15.6 An Extension to Ruby Symbols from agile web development
PDF .

15.6

groups = posts.group_by {|post| post.author_id}

# Rails has a shorthand notation for this. We could have written this
code as

groups = posts.group_by(&:author_id)

they say that & uses a proc function given below ,but the function is
even more confusing. .

class Symbol

def to_proc

Proc.new { |obj, *args| obj.send(self, *args) }

end

end

please do reply back if u have any solutions

Thank you

Regards,

Piyush Gupta

99161-33729

http://ctrlshiftesc.blogspot.com/

Reply all
Reply to author
Forward
0 new messages