[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    [ruby-core:107386] [Ruby master Bug#11064] #singleton_methods for objects with special singleton_cla
From:       "sawa (Tsuyoshi Sawada)" <noreply () ruby-lang ! org>
Date:       2022-01-31 5:02:47
Message-ID: redmine.journal-96288.20220131050246.1496 () ruby-lang ! org
[Download RAW message or body]

Issue #11064 has been updated by sawa (Tsuyoshi Sawada).


matz (Yukihiro Matsumoto) wrote in #note-1:
> `nil` does not have its singleton class, but `NilClass` plays the role of the \
> singleton class

I would appreciate it if @matz could kindly explain what the difference is between \
"being a singleton class" and "playing the role of a singleton class".

At the moment, I cannot understand at all how they are different. I am actually \
puzzled by a related comment by matz: https://bugs.ruby-lang.org/issues/12084#note-6. \
Why can we not simply say "`NilClass` is the singleton class of `nil`"?



----------------------------------------
Bug #11064: #singleton_methods for objects with special singleton_class returns an \
empty array https://bugs.ruby-lang.org/issues/11064#change-96288

* Author: rbjl (Jan Lelis)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
def nil.bla
  42  
end

# works
nil.bla #=> 42
nil.singleton_method(:bla) #=> #<Method: NilClass#bla>
NilClass.instance_methods.include? :bla #=> true

# does not work
nil.singleton_methods #=> []
~~~




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic