0

I have a challenge: to explore how method lookup works in Ruby. Here’s experimental code:

class Object
  def method_missing(*args)
    @count = @count.to_i + 1
    puts "Object: #{ @count }"
    super
  end
end

module Module1
  def method_missing(*args)
    puts 'Module1'
    super
  end
end

module Module2
  def method_missing(*args)
    puts 'Module2'
    super
  end
end

module Module3
  def method_missing(*args)
    puts 'Module3'
    super
  end
end

class Class1
  include Module1

  def method_missing(*args)
    puts 'Class1'
    super
  end
end

class Class2 < Class1
  include Module3
  include Module2

  def method_missing(*args)
    puts 'Class2'
    super
  end
end

test_obj = Class2.new
test_obj.testrun # non existing method

In Ruby 2.3.0 it seems works normally. But in Ruby 2.3.3 it has odd output with loops. Even if I comment two last lines (#test_obj = Class2.new and #test_obj.testrun) it will have looping in output, though must have nothing. Help to find the cause of problem, please.

rublen
  • 1
  • 1
  • You're bubbling up through to Object, and at that point calling `super` will give you a NoMethodError. – tadman Jan 11 '17 at 23:30
  • I suppose it's a problem of environment, I tried it in the codepad.io. Can it be? With Command Prompt with Ruby (Windows) it works nice. – rublen Jan 12 '17 at 11:35

0 Answers0