From: nobu@... Date: 2016-03-01T01:58:23+00:00 Subject: [ruby-core:74070] [Ruby trunk Feature#12113] Global method inside Delegator causes NameError Issue #12113 has been updated by Nobuyoshi Nakada. Correction: the infinite recursion was a bug in the patch, and fixed the branch. The trick of `Kernel` for [Bug #9155] is for the case a global method is called *before* the target object is set. It is for the backward compatibility and convenience, we may be better to warn to use `::` and remove it in the future. ---------------------------------------- Feature #12113: Global method inside Delegator causes NameError https://bugs.ruby-lang.org/issues/12113#change-57221 * Author: Oleg Antonyan * Status: Open * Priority: Normal * Assignee: ---------------------------------------- ~~~ruby def some_func puts '12' end class Klass < Delegator def initialize(obj) @obj = obj end def __getobj__ @obj end def func some_func #=> /home/oleg/.rbenv/versions/2.3.0/lib64/ruby/2.3.0/delegate.rb:85:in `instance_method': undefined method `some_func' for module `Kernel' (NameError) end end Klass.new(0).func ~~~ Delegator uses Kernel.instance_method (https://github.com/ruby/ruby/blob/trunk/lib/delegate.rb#L85) but: ~~~ruby ::Kernel.respond_to?(:some_func, true) #=> true ::Kernel.instance_method(:some_func) #=> `instance_method': undefined method `some_func' for module `Kernel' (NameError) ::Kernel.method(:some_func) #=> # ~~~ I think there should be `Kernel.method` instead of `instance_method` (in Delegator). Otherwise you get `respond_to?` == `true`, but cannot use this method and get an error. -- https://bugs.ruby-lang.org/ Unsubscribe: