Cool ruby code
While sipping from the firehose that is the ruby-talk mailing list, I came across this sweet bit of code:
[ruby]
class Integer
def factorial
return 1 if self <= 1
self * (self-1).factorial
end
end
> 6.factorial
> 720
[/ruby]
This is a nice illustration of ruby’s elegance. So much nicer than calling something like Math.Factorial(6).
