Last active
August 29, 2015 14:18
-
-
Save Luomint/24da23ec5980bb318c98 to your computer and use it in GitHub Desktop.
Why doesn't this work if the first acessor is at the bottom (2 scenarios)
This file contains 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
#This works: | |
class Ticket | |
def price # | |
@price # this will be moved to the bottom below on the 2nd example | |
end # | |
def price(amount) | |
if (amount * 100).to_i == amount * 100 | |
@price = amount | |
else | |
puts "The price seems to be malformed" | |
end | |
end | |
end | |
bil = Ticket.new | |
puts bil.price(59) | |
#but if we switch the first accessor place, it stops working sand says that there are too many arguments | |
class Ticket | |
def price(amount) | |
if (amount * 100).to_i == amount * 100 | |
@price = amount | |
else | |
puts "The price seems to be malformed" | |
end | |
end | |
def price # | |
@price # It's now here | |
end # | |
end | |
bil = Ticket.new | |
puts bil.price(59) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment