28
loading...
This website collects cookies to deliver better user experience
class Customer
attr_reader :orders
def initialize
@orders = []
end
def current_order
@orders.last
end
def current_order=(new_order)
@orders << new_order
"thank you for being our valued customer"
end
end
irb(main):001:0> definitely_not_the_owner = Customer.new
irb(main):002:0> definitely_not_the_owner.current_order = "pancakes"
=> "pancakes"
def current_order=(new_order)
@orders << new_order
"thank you for being our valued customer"
end
Note that for assignment methods the return value will be ignored when using the assignment syntax. Instead, the argument will be returned
The actual return value will be returned when invoking the method directly
irb(main):001:0> customer = Customer.new
irb(main):002:0> customer.current_order = "pancakes"
=> "pancakes"
irb(main):003:0> customer.public_send(:current_order=, "french toast")
=> "thank you for being our valued customer"