Skip to content

Instantly share code, notes, and snippets.

@Luomint
Last active August 29, 2015 14:18
Show Gist options
  • Save Luomint/24da23ec5980bb318c98 to your computer and use it in GitHub Desktop.
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 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