From: "jeremyevans0 (Jeremy Evans) via ruby-core" Date: 2024-07-09T06:45:31+00:00 Subject: [ruby-core:118516] [Ruby master Bug#20620] singleton_method undefined for module using "extend self" Issue #20620 has been updated by jeremyevans0 (Jeremy Evans). I don't think this is a bug. It does seem inconsistent, but only because the `all` argument to `singleton_methods` defaults to true. If you call `singleton_methods(false)`, then you get the behavior you would expect from the method name (only show actual singleton methods, not methods in modules that extend the object). ---------------------------------------- Bug #20620: singleton_method undefined for module using "extend self" https://bugs.ruby-lang.org/issues/20620#change-109037 * 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) # => # 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] # "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/