Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. def temperature_conversion_functions
  2. def ftoc(x)
  3. "Converts freezing temperature"
  4. ftoc(32) == 0
  5. end
  6.  
  7. "Converts boiling temperature"
  8. ftoc(212) == 100
  9. end
  10.  
  11. "Converts body temperature"
  12. ftoc(98.6) == 37
  13. end
  14.  
  15. "converts arbitrary temperature"
  16. ftoc(68) == 20
  17. end
  18. end
  19.  
  20. def ctof(x)
  21.  
  22. "converts freezing temperature"
  23. ctof(0) == 32
  24. end
  25.  
  26. "converts boiling temperature"
  27. ctof(100) == 212
  28. end
  29.  
  30. "converts arbitrary temperature"
  31. ctof(20) == 68
  32. end
  33.  
  34. "converts body temperature"
  35. ctof(37) == 98.6
  36. end
  37. end
  38.  
  39. end
  40.  
  41. x = 5
  42. if x > 3
  43. puts "x is greater than 3!"
  44. end
  45.  
  46. # This is a comment. The line below is executed code
  47. puts "Printing out this string"
  48.  
  49. def ftoc(x) # define the `ftoc(x)` method
  50. ftoc(32) == 9 # let's expand this line
  51. end
  52.  
  53. def ftoc(x)
  54. ( ftoc(32) == 9 ) == 9 # "expanded" once
  55. end
  56.  
  57. def ftoc(x)
  58. ( ( ftoc(32) == 9 ) == 9 ) == 9 # "expanded" twice
  59. end
  60.  
  61. module TemperatureConversion
  62. def TemperatureConversion.ftoc(f) # This is an example. More idiomatic way is shown below
  63. return (f - 32) * 5.0/9
  64. end
  65.  
  66. def self.ctof(c) # the 'self' in this line means/is-the-same-as 'TemperatureConversion'
  67. return c * 9.0/5 + 32
  68. end
  69. end
  70.  
  71. # now you can use the module and its methods
  72. # convert freezing
  73. puts TemperatureConversion.ftoc(32) # will output 0.0
  74.  
  75. def ftoc(x)
  76. "Converts freezing temperature"
  77. # What this is "recusion and check" supposed to be anyway?
  78. # It's recursive because it's inside the same (ftoc) method.
  79. ftoc(32) == 0
  80. end
  81.  
  82. "Converts boiling temperature"
  83. ftoc(212) == 100
  84. # Uhh, where does this `end` go? It's "unexpected".
  85. end
  86.  
  87. def ftoc(f)
  88. return (f - 32) * 5.0/9
  89. end
  90.  
  91. puts "42f is #{ftoc(42)}c"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement