SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: What is this syntax: &:day
-
Mar 2, 2006, 09:01 #1
- Join Date
- Jun 2004
- Location
- California
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What is this syntax: &:day
Hello,
I've been using Ruby and Rails for about 4 months now and although not often, I've seen this syntax from time to time. What does it mean? For example, in Rails's latest blog post:
Code:latest_transcripts.group_by(&:day).each do |day, transcripts| p "#{day} -> #{transcripts.map(&:class) * ', '}" end "2006-03-01 -> Transcript" "2006-02-28 -> Transcript" "2006-02-27 -> Transcript, Transcript" "2006-02-26 -> Transcript, Transcript"
-
Mar 2, 2006, 12:03 #2
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is "to_proc" defined for the Symbol class.
Code:class Symbol def to_proc proc { |obj, *args| obj.send(self, *args) } end end p ["abc", "def"].map(&:reverse) p [1, 2, 3].inject(&:+)
http://groups.google.com/group/comp....669444207f718b
-
Mar 2, 2006, 18:52 #3
- Join Date
- Jun 2004
- Location
- California
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wow. Very cool! Ruby never ceases to amaze me
Bookmarks