From: nobu@... Date: 2018-01-07T07:43:14+00:00 Subject: [ruby-core:84684] [Ruby trunk Bug#13774] for methods defined from procs, the binding of the resulting bound_method.to_proc does not have access to the original proc's closure environment Issue #13774 has been updated by nobu (Nobuyoshi Nakada). Once a `Proc` is bound as a method, the context of that method is not same as the based `Proc`, `receiver` for instance. ```ruby x = ->{} o = Object.new o.define_singleton_method(:x, x) p x.binding.receiver #=> main p o.method(:x).to_proc.binding.receiver #=> o ``` ---------------------------------------- Bug #13774: for methods defined from procs, the binding of the resulting bound_method.to_proc does not have access to the original proc's closure environment https://bugs.ruby-lang.org/issues/13774#change-69398 * Author: bughit (bug hit) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- ```ruby def foo o = Object.new local_var = 'local_var' method_lambda = ->{local_var} o.define_singleton_method(:lambda_method, &method_lambda) method_proc = o.method(:lambda_method).to_proc puts method_proc.() puts eval('local_var', method_lambda.binding) puts o.lambda_method puts eval('local_var', method_proc.binding) # undefined local variable or method `local_var' end foo ``` when executed as a method it has access to local_var as expected but the binding of the bound method proc does not in ruby 2.2.2 the above code crashes the vm -- https://bugs.ruby-lang.org/ Unsubscribe: