In current release of Ruby 2.0 (2.0.0p0), using
is an instance method of the top-level object main
, not that of Module
. And it's a private method. If you call it in class/module definition or method definition, a RuntimeError is raised.
"The scope of a refinement activated by main.using
is from the point just after main.using
is invoked to the end of the file where main.using
is invoked. However, when main.using
is invoked in a string given as the first argument of Kernel#eval
, Kernel#instance_eval
, or Module#module_eval
, the end of the scope is the end of the string."
You can read more about this in Refinements Specification.
For your test cases, you can write them with eval
and pass in the top level bindings, like the test cases in ruby source.
Refinements is still an experimental feature, it may change in future :-)