Issue #6126 has been updated by Dave B.



#- You can please yourself in your own programs by
#-  adding a couple of lines at the top.

#====================#
 class Object
   def yes?; self end
   def no?; !self end
 end
#====================#


def test(proposal_accepted)
  puts
  puts  proposal_accepted       ? 'Hooray!' : 'Booooo!'
  puts  proposal_accepted.yes?  ? 'Hooray!' : 'Booooo!'
  puts !proposal_accepted       ? 'Hooray!' : 'Booooo!'
  puts  proposal_accepted.no?   ? 'Hooray!' : 'Booooo!'
end


test true

#=> Hooray!
#=> Hooray!
#=> Booooo!
#=> Booooo!

test false

#=> Booooo!
#=> Booooo!
#=> Hooray!
#=> Hooray!

#- I wouldn't recommend it; your suggestion
#-  seems to require extra typing:

p '.yes?'.size - ''.size   #=> 5
p '.no?'.size - '!'.size   #=> 3

#-  daz

----------------------------------------
Feature #6126: Introduce yes/no constants aliases for true/false
https://bugs.ruby-lang.org/issues/6126

Author: Egor Homakov
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I propose to have predefined constants of TrueClass and FalseClass - yes/no accordingly.
Benefits:
1. 'truefalse'.size - 'yesno'.size = 4 (!)
2. much more understandable and reasonable words. Well known by everybody on this planet.
3. would be nice feature to introduce. Object#no? so we could use.
puts 'horay!' unless will_you_marry_me.no?
but it is very small thing, !will_you_marry_me behaves the same.. nevermind if it doesn't look useful
4. in further releases of ruby we could use them by default and keep true/false only for compatibility e.g.:
[2] pry(main)> true
=> yes

to discuss:
1. how to manage with true-false constants
2. do you like it?

P.S. I hope it is not crazy proposal for Ruby 4.9.3. I believe that ruby is agile enough. thoughts?


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