Skip to content

Instantly share code, notes, and snippets.

@darinthompson
Last active January 5, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darinthompson/e687427b5a19f811be11 to your computer and use it in GitHub Desktop.
Save darinthompson/e687427b5a19f811be11 to your computer and use it in GitHub Desktop.
temp converter
class Temperature
attr_accessor :temperature, :scale
def initialize(temperature = nil, scale = nil)
@temperature = temperature
@scale = scale
get_temperature
end
def get_temperature
if @temperature.nil?
puts "Temperature to be converted..."
@temperature = gets.chomp.to_i
puts "To Celcicus or to Farenheit (c/f)"
scale = gets.chomp.downcase
if scale == "f"
to_fahrenheit
else
to_celsius
end
else
if scale == "f"
to_fahrenheit
else
to_celsius
end
end
end
def to_fahrenheit
fahrenheit = (@temperature * (9.0/5.0)) + 32
puts fahrenheit
end
def to_celsius
celsius = (@temperature - 32) * (5.0/9.0)
puts celsius
end
end
temp1 = Temperature.new(20, "f")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment