From: shugo@... Date: 2015-02-03T08:33:12+00:00 Subject: [ruby-core:67975] [ruby-trunk - Bug #10818] Extrange behaviour when apliying a refinement inside eval Issue #10818 has been updated by Shugo Maeda. Seiei Higa wrote: > So, I expect following code works fine, but it raises `NoMethodError` in ruby 2.1.5, 2.2.0 Refinements should be activated in a lexical scope, so NoMethodError should be raised in that case. The problem originally reported is considered to be a bug, but it's difficult to fix because the environment of binding is updated by eval to share local variables (see vm_eval.c:1293), and refinement activation information is stored in the same area. Ko1, do you have any idea to fix this bug? ---------------------------------------- Bug #10818: Extrange behaviour when apliying a refinement inside eval https://bugs.ruby-lang.org/issues/10818#change-51363 * Author: Pablo Herrero * Status: Assigned * Priority: Normal * Assignee: Shugo Maeda * ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- 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. ```ruby module M refine String do def foobar; puts 'foobar'; end end end some_binding = class A; binding; end str1 = <