# your code goes here
def foo(var)
test = lambda do |&val|
val.call() + var
end
end
l = Proc.new do foo(56).call { foo(123).call() { 456 } } end
puts l.call() {55}
puts 456 + 123 + 56
class Foo
def blocky(val)
method_name = :foo
if self.class.method_defined?(method_name)
prev = self.class.instance_method(method_name).bind(self)
else
prev = lambda do |&block|
puts "prev_block"
block.call()
end
end
scopy = lambda do |&block|
puts "scopy"
prev.call() do
puts "scopy block"
block.call() + val
end
end
name = "test"
def self.("#{name}".to_sym)
999
end
self.class.define_method(method_name, scopy)
end
end
food = Foo.new
food.blocky(6)
food.blocky(9)
puts food.foo() {1}
def food.bar
puts 9999
end
food.bar()
bar = Foo.new
puts bar.foo() {2}
#puts bar.methods
puts bar.bar()
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCgpkZWYgZm9vKHZhcikKCXRlc3QgPSBsYW1iZGEgZG8gfCZ2YWx8CgkJdmFsLmNhbGwoKSArIHZhcgoJZW5kCmVuZAoKbCA9IFByb2MubmV3IGRvIGZvbyg1NikuY2FsbCB7IGZvbygxMjMpLmNhbGwoKSB7IDQ1NiB9IH0gZW5kCgpwdXRzIGwuY2FsbCgpIHs1NX0KCnB1dHMgNDU2ICsgMTIzICsgNTYKCmNsYXNzIEZvbwoJZGVmIGJsb2NreSh2YWwpCgkJbWV0aG9kX25hbWUgPSA6Zm9vCgkJaWYgc2VsZi5jbGFzcy5tZXRob2RfZGVmaW5lZD8obWV0aG9kX25hbWUpCgkJCXByZXYgPSBzZWxmLmNsYXNzLmluc3RhbmNlX21ldGhvZChtZXRob2RfbmFtZSkuYmluZChzZWxmKQoJCWVsc2UKCQkJcHJldiA9IGxhbWJkYSBkbyB8JmJsb2NrfAoJCQkJcHV0cyAicHJldl9ibG9jayIKCQkJCWJsb2NrLmNhbGwoKQoJCQllbmQKCQllbmQKCQkKCQlzY29weSA9IGxhbWJkYSBkbyB8JmJsb2NrfAoJCQlwdXRzICJzY29weSIKCQkJcHJldi5jYWxsKCkgZG8KCQkJCXB1dHMgInN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