rublen
rublen

Reputation: 1

Ruby 2.3.3: exploring method lookup

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.

Upvotes: 0

Views: 41

Answers (0)

Related Questions