Project

General

Profile

Actions

Backport #8686

closed

Calling define_singleton_method on an "extended self" module raises TypeError: compared with non class/module

Added by krieghan (Krieghan Riley) over 10 years ago. Updated over 10 years ago.


Description

The following code, issued through rake console, works fine on ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0],
but fails on ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2].

module A
extend self

def a
return "a"
end
end

def b
return "b"
end

a = A.method(:a)
A.define_singleton_method(:a, method(:b))
A.define_singleton_method(:a, a)

On ruby 2.0, the last line raises the following exception:

TypeError: compared with non class/module
from (irb):15:in define_singleton_method' from (irb):15 from ./Rakefile:17:in block in <top (required)>'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in call' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in block in execute'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in each' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in execute'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in block in invoke_with_call_chain' from ~/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in mon_synchronize'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in invoke_with_call_chain' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in invoke'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in invoke_task' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in block (2 levels) in top_level'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in each' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in block in top_level'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in run_with_threads' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in top_level'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in block in run' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in standard_exception_handling'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in run' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/bin/rake:33:in <top (required)>'
from ./vendor/bundler/ruby/2.0.0/bin/rake:23:in load' from ./vendor/bundler/ruby/2.0.0/bin/rake:23:in '2.0.0 :016 >

The result that I expect is that the original method "a" should be replaced back on the module (and in 1.9.3, that is exactly what happens).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0