Last active
November 15, 2015 00:06
-
-
Save kkchu791/8145a2b1a87a316dc62a to your computer and use it in GitHub Desktop.
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
class Person | |
attr_accessor :balance | |
def balance_test? | |
p "Your balance measurement is: #{@balance}" | |
if @balance > 500 | |
"You could be a gymnast" | |
elsif @balance > 100 && @balance < 500 | |
"You have normal balance" | |
else | |
"You either have terrible balance or drank too much" | |
end | |
end | |
end | |
gymnast = Person.new | |
gymnast.balance = 600 | |
p gymnast.balance_test? | |
drunkard = Person.new | |
drunkard.balance = 50 | |
p drunkard.balance_test? | |
#Why does that make some sense to not initialize the necessary "@balance" variable in the initialize? | |
#The @balance variable was set by the attr method therefore does not need the initialize method. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment