Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def temperature_conversion_functions
- def ftoc(x)
- "Converts freezing temperature"
- ftoc(32) == 0
- end
- "Converts boiling temperature"
- ftoc(212) == 100
- end
- "Converts body temperature"
- ftoc(98.6) == 37
- end
- "converts arbitrary temperature"
- ftoc(68) == 20
- end
- end
- def ctof(x)
- "converts freezing temperature"
- ctof(0) == 32
- end
- "converts boiling temperature"
- ctof(100) == 212
- end
- "converts arbitrary temperature"
- ctof(20) == 68
- end
- "converts body temperature"
- ctof(37) == 98.6
- end
- end
- end
- x = 5
- if x > 3
- puts "x is greater than 3!"
- end
- # This is a comment. The line below is executed code
- puts "Printing out this string"
- def ftoc(x) # define the `ftoc(x)` method
- ftoc(32) == 9 # let's expand this line
- end
- def ftoc(x)
- ( ftoc(32) == 9 ) == 9 # "expanded" once
- end
- def ftoc(x)
- ( ( ftoc(32) == 9 ) == 9 ) == 9 # "expanded" twice
- end
- module TemperatureConversion
- def TemperatureConversion.ftoc(f) # This is an example. More idiomatic way is shown below
- return (f - 32) * 5.0/9
- end
- def self.ctof(c) # the 'self' in this line means/is-the-same-as 'TemperatureConversion'
- return c * 9.0/5 + 32
- end
- end
- # now you can use the module and its methods
- # convert freezing
- puts TemperatureConversion.ftoc(32) # will output 0.0
- def ftoc(x)
- "Converts freezing temperature"
- # What this is "recusion and check" supposed to be anyway?
- # It's recursive because it's inside the same (ftoc) method.
- ftoc(32) == 0
- end
- "Converts boiling temperature"
- ftoc(212) == 100
- # Uhh, where does this `end` go? It's "unexpected".
- end
- def ftoc(f)
- return (f - 32) * 5.0/9
- end
- puts "42f is #{ftoc(42)}c"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement