Project

General

Profile

Actions

Bug #20620

closed

singleton_method undefined for module using "extend self"

Added by dentarg (Patrik Ragnarsson) 4 months ago. Updated 27 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
[ruby-core:118514]

Description

Is this a bug? I expected ExtendSelf.singleton_method(:foo) to work when ExtendSelf.singleton_methods worked and :foo was in the list returned.

# singleton_method.rb
class Klass
  def self.foo
  end
end

module ExtendSelf
  extend self

  def foo
  end
end

p RUBY_DESCRIPTION

p "Klass"
p Klass.singleton_methods      # => [:foo]
p Klass.singleton_method(:foo) # => #<Method: Klass.foo() singleton_method.rb:2>

p "ExtendSelf"
p ExtendSelf.singleton_methods      # => [:foo]
p ExtendSelf.singleton_method(:foo) # => singleton_method.rb:19:in `singleton_method': undefined singleton method `foo' for `ExtendSelf' (NameError)
$ docker run --rm -it -v $(pwd):/app -w /app rubylang/ruby:master-nightly-jammy
Unable to find image 'rubylang/ruby:master-nightly-jammy' locally
master-nightly-jammy: Pulling from rubylang/ruby
...
Digest: sha256:922037b184b897786a26b2460f70a66139f87dce67f20ddf760cd4186790ed9f

root@9807305c322a:/app# ruby -v
ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]

root@9807305c322a:/app# ruby singleton_method.rb
"ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]"
"Klass"
[:foo]
#<Method: Klass.foo() singleton_method.rb:2>
"ExtendSelf"
[:foo]
singleton_method.rb:21:in 'Kernel#singleton_method': undefined singleton method 'foo' for 'ExtendSelf' (NameError)
Actions

Also available in: Atom PDF

Like0
Like1Like0Like0Like0Like0