It is not possible in "plain" ruby because Rails extends the Symbol
class with the possibility of converting it into a Proc (that's what
happens when you precede something with a &). From the Rails source
code:
unless :to_proc.respond_to?(:to_proc)
class Symbol
# Turns the symbol into a simple proc, which is especially useful
for enumerations. Examples:
#
# # The same as people.collect { |p| p.name }
# people.collect(&:name)
#
# # The same as people.select { |p| p.manager? }.collect { |p|
p.salary }
# people.select(&:manager?).collect(&:salary)
def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end
end
end
And it does come very handy indeed.
Balint
On Feb 6, 1:07 am, Kenneth McDonald <[email protected]>
wrote:
> I've seen a claim on the web that &:f is just Ruby shorthand for &proc
> { |i| i.f }, but I've certainly never been able to get this &:f
> notation to work in standard ruby.
>
> Thanks,
> Ken
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---