Project

General

Profile

Actions

Bug #10818

closed

Extrange behaviour when apliying a refinement inside eval

Added by pabloh (Pablo Herrero) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
[ruby-core:67945]

Description

When you activate a refinement inside an a string using eval with a binding, the refinement is sill active the next time you call eval with the same binding.
Strangely enough, this will only happen if there is an assignment at the code evaluated the first time. If you delete the assignment everything works as expected.

module M
  refine String do
    def foobar; puts 'foobar'; end
  end
end

some_binding = class A; binding; end


str1 = <<EOF
a = 'something' # Without this everything works as expected
using M
'str'.foobar # Works fine
EOF

str2 = <<EOF
'str'.foobar # This time should fail but it doesn't
EOF

eval str1, some_binding
eval str2, some_binding

Acording to the RefinmentsSpec: "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."

Which contradicts with this code's behavior.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0