Using ‘?’ for wierdness

? is Ruby shorthand for referencing a character.

   irb(main):020:0> ?a => 97 
   irb(main):021:0> ?a == "a"[0] => true
   irb(main):014:0> ?? => 63 
   irb(main):015:0> !?? => false 
   irb(main):016:0> !!?? => true

Since ?? equals 63, it is equivalent to true in a boolean test. That means we can negate it with a bang!

Categories: ruby

Leave a Reply

Your email address will not be published. Required fields are marked *

*