# your code goes here
module Foo
def memo(name, &block)
define_method(name) do
instance_variable_set("@#{name}", block.call) unless instance_variables.include?("@#{name}".to_sym)
instance_variable_get("@#{name}")
end
end
end
Class.include(Foo)
class T
memo :me do 6 + 4 end
memo(:you) { 6 + 4 }
memo(:them, &(->{ 6 + 4 }))
end
t = T.new
puts t.me
puts t.you
puts t.them
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCm1vZHVsZSBGb28KCWRlZiBtZW1vKG5hbWUsICZibG9jaykKCQlkZWZpbmVfbWV0aG9kKG5hbWUpIGRvCgkJCWluc3RhbmNlX3ZhcmlhYmxlX3NldCgiQCN7bmFtZX0iLCBibG9jay5jYWxsKSB1bmxlc3MgaW5zdGFuY2VfdmFyaWFibGVzLmluY2x1ZGU/KCJAI3tuYW1lfSIudG9fc3ltKQoJCQlpbnN0YW5jZV92YXJpYWJsZV9nZXQoIkAje25hbWV9IikKCQllbmQKCWVuZAplbmQKCkNsYXNzLmluY2x1ZGUoRm9vKQoKY2xhc3MgVAoJbWVtbyA6bWUgZG8gNiArIDQgZW5kCgltZW1vKDp5b3UpIHsgNiArIDQgfQoJbWVtbyg6dGhlbSwgJigtPnsgNiArIDQgfSkpCmVuZAoKdCA9IFQubmV3CnB1dHMgdC5tZQpwdXRzIHQueW91CnB1dHMgdC50aGVt