Created
November 13, 2013 05:22
-
-
Save rbk/7444164 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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