Customer = Struct.new(:name, :address) do
p self
def greeting
"Hello!"
end
end
dave = Customer.new("Dave", "123 Main")
p dave.name #=> "Dave"
p dave.greeting #=> "Hello Dave!"
p greeting #=> expected to raise NameError
On CRuby, the last line raises a NameError exception because the method greeting is not defined on top-level (but an accessor of Customer). It is an expected behavior.
#<Class:0x00157a1b98f990>
"Dave"
"Hello!"
a.rb:11:in `<main>': undefined local variable or method `greeting' for main:Object (NameError)
On mruby, it shows "Hello!" and self in the block is not an instance of Customer but main(!):
main
"Dave"
"Hello!"
"Hello!"
On CRuby, the last line raises a NameError exception because the method
greetingis not defined on top-level (but an accessor of Customer). It is an expected behavior.On mruby, it shows "Hello!" and
selfin the block is not an instance of Customer but main(!):