« Timeline | Main | What’s Shiny and New in Ruby 1.8.0? »

February 01, 2005

Rubyisms (#1)

You won't find C-like #ifdefs (conditional compilation) in Ruby. The following approach can be used instead.

if RUBY_PLATFORM =~ /linux/
  def method_name
  .... # linux-specific code
  end
elsif RUBY_PLATFORM =~ /win32/
  def method_name
  .... # win32-specific code
  end
else
  def method_name
  ....
  end
end
Based on code from The Ruby Way by Hal Fulton.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/3087162/31463280

Listed below are links to weblogs that reference Rubyisms (#1):

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

This is really cool.

Post a comment

If you have a TypeKey or TypePad account, please Sign In