I am a bit puzzled on why this piece of code does not work:
def create(type)
Module.new do
def foo
type
end
end
end
When calling foo
on the returned Module, type
is not defined.
Am I supposed to use a Proc or a lambda to capture the scope within the create method?
(I probably have done too much JavaScript recently)
tl;dr
How can I create Module at runtime with methods that use variables available at the time of creation?