I would like to call const_missing in an instance_eval, but seem to be missing something:
class A
def self.const_missing(c)
puts "Constant missing: #{c}"
end
def method_missing(m, *args, &block)
puts "Method missing: #{m}"
end
end
# Works:
a = A.new
a.myMethod # OK: "Method missing: myMethod"
a.MYCONST # Sort of OK: "Method missing: MYCONST"
# Doesn't work
a.instance_eval {
myMethod # OK: "Method missing: myMethod"
MYCONST # uninitialized constant MYCONST (NameError)
}
Q: Where does the const_missing call in the instance_eval go? How can redirect it to class A? (Ruby 1.9.3 if this matters)
Context: I am writing a small DSL, where upper-case letters are used as state names.
DSL.evaluate {
ENTER_STATE_A
WAIT_FOR_INPUT
}
These should be mapped to methods, but I would like to keep them upper case.