Feature #12515
Create "Boolean" superclass of TrueClass / FalseClass
説明
Since Ruby 2.4 is unifying Bignum/Fixnum into Integer (https://bugs.ruby-lang.org/issues/12005), it seems reasonable to do something similar for TrueClass / FalseClass, and create a proper Boolean hierarchy. The implementation would be fairly straightforward and should be back compat unless someone already has a "Boolean" class at toplevel out there.
Given the compatibility implications of Integer, this Boolean proposal is even less intrusive.
Sample implementation:
class Boolean < BasicObject; end class TrueClass < Boolean; end class FalseClass < Boolean; end
履歴
#1
[ruby-core:76108]
Shyouhei Urabe が約3時間前に更新
Loren Segal wrote:
should be back compat unless someone already has a "Boolean" class at toplevel out there.
You failed here.
https://github.com/search?l=ruby&q=%22class+Boolean%22&type=Code
https://rubygems.org/search?query=Boolean
I guess it's too late.
#2
[ruby-core:76109]
Olivier Lacan が約3時間前に更新
Shyouhei Urabe wrote:
You failed here.
This admittedly could be lost in translation but I don't think this a very nice way to react to Loren's proposal. He didn't fail here. He just proposed something. You either think it's a good idea or a bad idea. I wish you could provide your opinion a bit more kindly.
https://github.com/search?l=ruby&q=%22class+Boolean%22&type=Code
https://rubygems.org/search?query=BooleanI guess it's too late.
I can change the search query to Integer and provide similarly dubious reasons why Integer would be bad idea:
https://github.com/search?l=ruby&q=%22class+Integer%22&type=Code
https://rubygems.org/search?query=Integer
I don't think this is very solid counterpoint.
#3
[ruby-core:76110]
Loren Segal が約3時間前に更新
Shyouhei Urabe wrote:
https://github.com/search?l=ruby&q=%22class+Boolean%22&type=Code
https://rubygems.org/search?query=BooleanI guess it's too late.
As Olivier pointed out, isn't this an argument to revert the Integer patch? Why is the Integer change okay but not Boolean?
#4
[ruby-core:76111]
Loren Segal が約2時間前に更新
edit: as a sidenote, adding a Boolean class to Ruby-core is unlikely to break any of the linked code, because Ruby is just defining an empty Boolean class. Existing libraries will just re-open the class as normal.
#5
[ruby-core:76113]
Daniel Berger が36分前に更新
This was brought up in the past a lot:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/96321
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/186881
There's also this: http://stackoverflow.com/questions/3192978/why-does-ruby-have-trueclass-and-falseclass-instead-of-a-single-boolean-class
#6
[ruby-core:76114]
Shyouhei Urabe が14分前に更新
- I'm not a big fan of Integer, too. However,
- Integer has been there since the beginning. It was just not used before. You are always free to reopen this class. Boolean on the other hand, is something new. The situation is different.
- Because most wild Boolean implementation I have seen inherits Object (or depending on project ActiveRecord::Base), I'm sorry I guess Loren's suggested implementation that inherits BasicObject won't interface.