From: shugo@... Date: 2015-02-04T03:01:45+00:00 Subject: [ruby-core:67993] [ruby-trunk - Bug #10818] Extrange behaviour when apliying a refinement inside eval Issue #10818 has been updated by Shugo Maeda. Assignee changed from Shugo Maeda to Yukihiro Matsumoto Seiei Higa wrote: > > Refinements should be activated in a lexical scope, so NoMethodError should be raised in that case. > > How about this case? It might be a bug too. > [The docs of Binding](http://www.ruby-doc.org/core-2.2.0/Binding.html) says > > > Objects of class Binding encapsulate the execution context at some particular place in the code and retain this context for future use. The variables, methods, value of self, and possibly an iterator block that can be accessed in this context are all retained. > > and [docs of Binding#eval](http://www.ruby-doc.org/core-2.2.0/Binding.html#method-i-eval) says > > > Evaluates the Ruby expression(s) in string, in the binding���s context. > > It's sounds good to retain refinements in binding's context. The documentation of Binding should not justify the behavior of refinements, because it was written before refinements are introduced into Ruby. The original version of refinements are designed to be a more dynamic feature, but it was changed to be more static to avoid confusion caused by implicit refinement activation. I'd like to hear Matz's opinion. ---------------------------------------- Bug #10818: Extrange behaviour when apliying a refinement inside eval https://bugs.ruby-lang.org/issues/10818#change-51379 * Author: Pablo Herrero * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto * 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 = <