Project

General

Profile

Actions

Bug #9393

closed

Strange behavior of DelegateClass + loop + method_missing

Bug #9393: Strange behavior of DelegateClass + loop + method_missing

Added by fxposter (Pavel Forkert) about 12 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

Having the following class in Ruby 2.1:

require 'delegate'

class A < DelegateClass(Hash)
  def a
    loop do
      ::Kernel.p 'A'
      break
    end
  end
end

After calling A.new({}).a the output is "A".

However if method_missing is added to the class:

class A < DelegateClass(Hash)
  def a
    loop do
      ::Kernel.p 'A'
      break
    end
  end

  def method_missing(method, *args, &block)
    ::Kernel.p method
  end
end

Then after calling A.new({}).a, the output is somewhat unexpected: :loop. That actually means that :loop method cannot be found and the block within the loop will not run. Is that the right behavior?

Ruby 2.0 returns "A" in both cases.

Updated by nobu (Nobuyoshi Nakada) about 12 years ago Actions #1

  • Description updated (diff)
  • Status changed from Open to Closed

Correct behavior.
loop is also delegated to the target object now.

Updated by usa (Usaku NAKAMURA) about 12 years ago Actions #2 [ruby-core:60484]

  • Status changed from Closed to Rejected
Actions

Also available in: PDF Atom