Rubinius allows method to be bound where MRI does not #32

Closed
brixen opened this Issue Oct 7, 2009 · 1 comment

Comments

Projects
None yet
2 participants
Owner

brixen commented Oct 7, 2009

Reported by wycats as Lighthouse issue 781.

module Annotations
  def self.extend(klass)
    klass.class_eval { include Annotation }
  end
  
  def annotate(module_name, &block)    
    new_module = Module.new do
      @@execute_method = Annotations.const_get(module_name).method(:execute)
      
      def self.method_added(name)
        original_method = instance_method(name)
        remove_method(name)
        
        method_module = Module.new do
          define_method(name, original_method)
        end
        
        execute_module = Module.new do
          define_method(name, @@execute_method)
        end
        
        include method_module
        include execute_module
      end
    end
    
    new_module.module_eval(&block)
    
    include new_module
  end
end

module Annotations
  module Logging
    def self.execute(*args, &block)
      puts "ARGS: #{args}"
      super
    end
  end
end

class Foo
  extend Annotations
  
  annotate :Logging do
    def hello
      puts "HELLO"
    end
  end
end

puts Foo.new.hello

Result in MRI:

annotations.rb:52:in `hello': singleton method bound for a different object (TypeError)
    from annotations.rb:52

Result in Rubinius

ARGS: 
An exception occurred running annotations.rb
    No method 'execute' on Annotations::Logging (Module) (NoMethodError)

Backtrace:
  Kernel(Module)#execute (method_missing) at kernel/delta/kernel.rb:45
          Annotations::Logging.execute at annotations.rb:37
                           Method#call at kernel/common/method.rb:70
        Rubinius::DelegatedMethod#call at kernel/common/delegated_method.rb:17
                       main.__script__ at annotations.rb:52
    Rubinius::CompiledMethod#as_script at kernel/common/compiled_method.rb:216
           Compiler::Utils.single_load at kernel/compiler/compile.rb:244
   Compiler::Utils.load_from_extension at kernel/compiler/compile.rb:329
               Rubinius::Loader#script at kernel/loader.rb:326
                 Rubinius::Loader#main at kernel/loader.rb:406
                     Object#__script__ at kernel/loader.rb:454
Owner

evanphx commented Mar 27, 2010

Add check when invoking an UnboundMethod. Closed by c357e2d.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment