Q1~Q3 - mfham/mfham.github.io GitHub Wiki

class Foo < BasicObject                                                                                                                      
  attr_reader :count                                                                                                                         
                                                                                                                                             
  def initialize                                                                                                                             
    @count = 0                                                                                                                               
  end                                                                                                                                        
                                                                                                                                             
  def !                                                                                                                                      
    @count += 1                                                                                                                              
    super                                                                                                                                    
  end                                                                                                                                        
end                                                                                                                                          
                                                                                                                                             
foo = Foo.new                                                                                                                                
                                                                                                                                             
!foo                                                                                                                                         
puts foo.count # Q1                                                                                                                          
                                                                                                                                             
!!!foo                                                                                                                                       
puts foo.count # Q2                                                                                                                          
                                                                                                                                             
puts 'foo' if !foo                                                                                                                           
puts foo.count # Q3   
# Q1: 1
# Q2: 2
# Q3: 3
⚠️ **GitHub.com Fallback** ⚠️