ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91640] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
@ 2019-02-28 11:47 ` sawadatsuyoshi
  2019-02-28 14:59 ` [ruby-core:91645] " shevegen
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: sawadatsuyoshi @ 2019-02-28 11:47 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been reported by sawa (Tsuyoshi Sawada).

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

* [ruby-core:91645] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
  2019-02-28 11:47 ` [ruby-core:91640] [Ruby trunk Bug#15627] Appearance of custom singleton classes sawadatsuyoshi
@ 2019-02-28 14:59 ` shevegen
  2019-02-28 15:33 ` [ruby-core:91646] " eregontp
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: shevegen @ 2019-02-28 14:59 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been updated by shevegen (Robert A. Heiler).


I sort of agree.

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627#change-76909

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

* [ruby-core:91646] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
  2019-02-28 11:47 ` [ruby-core:91640] [Ruby trunk Bug#15627] Appearance of custom singleton classes sawadatsuyoshi
  2019-02-28 14:59 ` [ruby-core:91645] " shevegen
@ 2019-02-28 15:33 ` eregontp
  2019-03-04  0:43 ` [ruby-core:91657] " nobu
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: eregontp @ 2019-02-28 15:33 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been updated by Eregon (Benoit Daloze).


`singleton_class` and `class` are different by design.
They are only the same for `true`, `false` and `nil`.

Having the singleton class get named when assigning it to a constant sounds like a possible feature.
Although it doesn't seem common to assign a singleton class to a constant.

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627#change-76910

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

* [ruby-core:91657] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-02-28 15:33 ` [ruby-core:91646] " eregontp
@ 2019-03-04  0:43 ` nobu
  2019-03-09 12:52 ` [ruby-core:91729] " mame
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: nobu @ 2019-03-04  0:43 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been updated by nobu (Nobuyoshi Nakada).


At first, as no syntax to name a singleton class like ordinary classes/modules, singleton classes cannot have a name.
And name-by-assignment is a “best effort” (or “better than nothing”).

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627#change-76919

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

* [ruby-core:91729] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-03-04  0:43 ` [ruby-core:91657] " nobu
@ 2019-03-09 12:52 ` mame
  2019-03-10 16:33 ` [ruby-core:91735] " hanmac
  2019-03-10 16:41 ` [ruby-core:91737] " mame
  6 siblings, 0 replies; 7+ messages in thread
From: mame @ 2019-03-09 12:52 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been updated by mame (Yusuke Endoh).


Rather, it looks a bug that `#singleton_class` returns a non-singleton class:

```
p Object.new.singleton_class.singleton_class? #=> true

p true .singleton_class.singleton_class? #=> false
p false.singleton_class.singleton_class? #=> false
p nil  .singleton_class.singleton_class? #=> false

1.singleton_class #=> can't define singleton (TypeError)
```

It looks reasonable to raise an exception like `1.singleton_class`.  (But I'm unsure if it is worth enough to break compatibility.)

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627#change-77005

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

* [ruby-core:91735] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-03-09 12:52 ` [ruby-core:91729] " mame
@ 2019-03-10 16:33 ` hanmac
  2019-03-10 16:41 ` [ruby-core:91737] " mame
  6 siblings, 0 replies; 7+ messages in thread
From: hanmac @ 2019-03-10 16:33 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been updated by Hanmac (Hans Mackowiak).


@mame it is by design that true, false and nil has their class work as singleton class so you can do:

```ruby

def true.bla
  # something
end
```

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627#change-77012

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

* [ruby-core:91737] [Ruby trunk Bug#15627] Appearance of custom singleton classes
       [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-03-10 16:33 ` [ruby-core:91735] " hanmac
@ 2019-03-10 16:41 ` mame
  6 siblings, 0 replies; 7+ messages in thread
From: mame @ 2019-03-10 16:41 UTC (permalink / raw)
  To: ruby-core

Issue #15627 has been updated by mame (Yusuke Endoh).


Wow.

```
def true.foo; end
p TrueClass.instance_methods.include?(:foo) #=> true
```

I didn't know, thanks.  I have used Ruby for fifteen years, but Ruby still brings fresh surprise to me.

----------------------------------------
Bug #15627: Appearance of custom singleton classes
https://bugs.ruby-lang.org/issues/15627#change-77013

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When I have a singleton class `AClass` of an instance `a` of a custom class `A`,


```ruby
class A; end
a = A.new
AClass = a.singleton_class
```

i) even though the singleton class of `nil`, `false`, and `true` are referred to by their assigned constant names, the singleton class `AClass` of `a` is not:

```ruby
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
```

ii) even though the singleton class of `nil`, `false`, and `true` appear as their class, the singleton class `AClass` of `a` does not:

```ruby
nil.class #=> NilClass
false.class #=> FalseClass
true.class #=> TrueClass
a.class #=> A
```

This contrast between `nil`, `false`, and `true` on the one hand and `a` on the other is confusing. I am actually not sure if this is intended behaviour It may be related to
* https://bugs.ruby-lang.org/issues/15608
* https://bugs.ruby-lang.org/issues/14895

I expect `AClass` to behave the same as with `NilClass`, `FalseClass`, and `TrueClass`. I expect:

```ruby
a.singleton_class #=> AClass
a.class #=> AClass
```

If the current behaviour is intended, I would like this to become a feature request.



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

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

end of thread, other threads:[~2019-03-10 16:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15627.20190228114727@ruby-lang.org>
2019-02-28 11:47 ` [ruby-core:91640] [Ruby trunk Bug#15627] Appearance of custom singleton classes sawadatsuyoshi
2019-02-28 14:59 ` [ruby-core:91645] " shevegen
2019-02-28 15:33 ` [ruby-core:91646] " eregontp
2019-03-04  0:43 ` [ruby-core:91657] " nobu
2019-03-09 12:52 ` [ruby-core:91729] " mame
2019-03-10 16:33 ` [ruby-core:91735] " hanmac
2019-03-10 16:41 ` [ruby-core:91737] " mame

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 read-only IMAP folder(s) and NNTP newsgroup(s).