Search code examples
logictruthtable

Is there an easy way to learn truth tables?


I'm following an online tutorial for Ruby and I'm at a point where it's mentioning truth tables and how I need to learn them before proceeding.

Is there an easy way to learn them? Do I just need to learn what constitutes as true and false?


Solution

  • You don't need truth tables to learn Ruby, though they're not that hard, they look scarier than they are.

    To learn what this tutorial is trying to teach you, go to the command line and type irb which will open up an interactive Ruby for you, called a REPL. You can play around with the boolean expressions, which just means code that deals with true and false:

    1.9.3-p0 :001 > true || false
     => true 
    1.9.3-p0 :002 > (true || false) && false
     => false 
    1.9.3-p0 :003 > false && true
     => false 
    1.9.3-p0 :004 > false ^ true
     => true 
    1.9.3-p0 :005 > !true
     => false 
    1.9.3-p0 :006 > !!true
     => true
    1.9.3-p0 :007 > exit
    

    Whatever they're trying to teach you with truth tables, you can learn better with a little experimentation in an interactive environment.