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.
def method_name
.... # linux-specific code
end
elsif RUBY_PLATFORM =~ /win32/
def method_name
.... # win32-specific code
end
else
def method_name
....
end
end
This is really cool.
Posted by: Anonymous | February 01, 2005 at 09:13 PM