Skip to content

Instantly share code, notes, and snippets.

@jessieay
Created June 15, 2012 16:51
Show Gist options
  • Save jessieay/2937542 to your computer and use it in GitHub Desktop.
Save jessieay/2937542 to your computer and use it in GitHub Desktop.
Baby's first instance variables
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