Ruby classes are open, so you can simply do:
class Array def sum inject(0) { |sum,v| sum+=v } end end
You can also redefine existing methods, but you'll have to be very careful with that. alias is your friend.
Cheers, Max
Ruby classes are open, so you can simply do:
class Array def sum inject(0) { |sum,v| sum+=v } end end
You can also redefine existing methods, but you'll have to be very careful with that. alias is your friend.
Cheers, Max
where would that code snippet go?
In the application controller?
No. Create a new file under lib, for example array_extensions.rb and you should be fine.
Max