Created
June 15, 2012 16:51
-
-
Save jessieay/2937542 to your computer and use it in GitHub Desktop.
Baby's first instance variables
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
def Calculator | |
def add(num1,num2) | |
@num1= num1 | |
@num2 = num2 | |
output("sum", num1 + num2) | |
end | |
def subtract(num1,num2) | |
@num1= num1 | |
@num2 = num2 | |
output("difference", num1 - num2) | |
end | |
def multiply(num1,num2) | |
@num1= num1 | |
@num2 = num2 | |
output("product", num1 * num2) | |
end | |
def divide(num1,num2) | |
@num1= num1 | |
@num2 = num2 | |
output("quotient", num1.to_f / num2) | |
end | |
def output(operator, result) | |
"The #{operator} of #{@num1} and #{@num2} is #{result}." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment