ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self"
@ 2024-07-09  5:47 dentarg (Patrik Ragnarsson) via ruby-core
  2024-07-09  6:45 ` [ruby-core:118516] " jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dentarg (Patrik Ragnarsson) via ruby-core @ 2024-07-09  5:47 UTC (permalink / raw)
  To: ruby-core; +Cc: dentarg (Patrik Ragnarsson)

Issue #20620 has been reported by dentarg (Patrik Ragnarsson).

----------------------------------------
Bug #20620: singleton_method undefined for module using "extend self"
https://bugs.ruby-lang.org/issues/20620

* Author: dentarg (Patrik Ragnarsson)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-07-08T21:43:28Z master e500222de1) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Is this a bug? I expected `ExtendSelf.singleton_method(:foo)` to work when `ExtendSelf.singleton_methods` worked and `:foo` was in the list returned.

```ruby
# 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)
```

```shell
$ 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)
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-03  6:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-09  5:47 [ruby-core:118514] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" dentarg (Patrik Ragnarsson) via ruby-core
2024-07-09  6:45 ` [ruby-core:118516] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-08-01  9:32 ` [ruby-core:118764] " matz (Yukihiro Matsumoto) via ruby-core
2024-09-12 14:23 ` [ruby-core:119138] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-10-03  6:53 ` [ruby-core:119421] " matz (Yukihiro Matsumoto) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).