Module: RubyLabs::IntroLab
- Defined in:
- lib/introlab.rb
Overview
IntroLab
The IntroLab module has Ruby code described in from Chapter 2 of Explorations in Computing. These simple examples illustrate how methods are defined in Ruby.
Instance Method Summary collapse
-
#celsius(f) ⇒ Object
Convert the temperature
f
(in degrees Fahrenheit) into the equivalent temperature in degrees Celsius. -
#countertop(x) ⇒ Object
Compute the area of a 5-sided counter that is a square with a missing triangle shape.
-
#fahrenheit(c) ⇒ Object
Stub for a method to convert temperature
c
(in degrees Celsius) into the equivalent temperature in degrees Fahrenheit.
Instance Method Details
#celsius(f) ⇒ Object
Convert the temperature f
(in degrees Fahrenheit) into the equivalent temperature in degrees Celsius.
– :begin :celsius
31 32 33 |
# File 'lib/introlab.rb', line 31 def celsius(f) (f - 32) * 5 / 9 end |
#countertop(x) ⇒ Object
Compute the area of a 5-sided counter that is a square with a missing triangle shape. The parameter x
is the length of one side of the square.
– :begin :countertop
19 20 21 22 23 |
# File 'lib/introlab.rb', line 19 def countertop(x) square = x**2 triangle = ((x/2)**2) / 2 return square - triangle end |
#fahrenheit(c) ⇒ Object
Stub for a method to convert temperature c
(in degrees Celsius) into the equivalent temperature in degrees Fahrenheit
– :begin :fahrenheit
41 42 43 |
# File 'lib/introlab.rb', line 41 def fahrenheit(c) # your expression goes here end |