Your favourite bit of Ruby code?

by Satish Talim on February 9, 2007

An interesting thread at Ruby_talk is ‘Your favorite bit of Ruby code.’


Setting aside time for learning HTML is beneficial to any web host.


John Carter
from New Zealand has this interesting snippet of code:

# Ruby is Objects all the way down and open for extension...
class Integer
  def factorial
    return 1 if self <= 1
    self * (self-1).factorial
  end
end

puts 6.factorial

Technorati Tags:

Posted by Satish Talim

{ 2 comments… read them below or add one }

geshido February 10, 2007 at 4:28 pm

My favorite is:

def debug(message)
if DEBUG == 1 and (block_given? ? yield : true )
puts “DEBUG: #{message}”
end
end

Reply

Ruby Expert September 16, 2007 at 8:18 pm

John’s example illustrates Ruby’s elegance and extensibility. My favorite is the file search – http://www.rubytips.org/about/

Reply

Leave a Comment

Previous post:

Next post: