Skip to content

Instantly share code, notes, and snippets.

@rbk
Created November 13, 2013 05: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 rbk/7444164 to your computer and use it in GitHub Desktop.
Save rbk/7444164 to your computer and use it in GitHub Desktop.
test
# distance class
class Distance
attr_accessor :value, :unit
@@var # class variable
@var # object variable
# @km = "miles / 0.62136"
# @miles = "km * 0.6214"
def initialize( value, unit )
@value = value
@unit = unit
end
# def output_unit
# if @unit.downcase == "m"
# "Miles"
# else
# "Kilometers"
# end
# end
def convert( value, unit )
if unit.downcase == "m"
# convert miles to kilos
value / 0.621371
elsif unit.downcase == "k"
#convert km to miles
value * 1.60934
else
value
end
end
def + test
print test.value
print test.unit
end
end
d1 = Distance.new(1, "m")
d2 = Distance.new(1, "k")
puts d1 + d2
puts d1.value
puts d1.unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment