Sunday, December 19, 2010

Test: Does this syntax highlighter work?

#Old, not-so-useful version:

print "Hello. Please enter a Celsius value: "
celsius = gets
fahrenheit = (celsius.to_i * 9.0 / 5) + 32
print "The farenheit equivalent is "
print fahrenheit
puts "."






#New and improved version that accomplishes temperature conversion as a method

class Numeric
  def c2f  # this is a method 
    self* 9.0 / 5 + 32
  end  
end  

#Example use cases of this method
current_farenheit = 12.c2f 
puts current_farenheit

No comments:

Post a Comment