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?
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?
What's important is understanding the functions that are used to compute truth tables. When you understand the functions the truth tables will be obvious.
A OR B: Either A or B # cream OR sugar, T if either (or both), F if neither
A AND B: Both A and B # cream AND sugar, T only when the coffee has both
A XOR B: One but not both # T only if sugar but no cream or if cream but no sugar
NOT A: Kind of obvious # NOT sugar, true if the tea has no sugar
A NAND B: NOT (A AND B) # T unless both cream and sugar are in the tea
A NOR B: NOT (A OR B) # T only if there is no sugar and also no cream
It might help if you substitute those abstract true
and false
values for obvious true and false statements.
Is this statement true?
Sugar is sweet AND grass is blue.
No, that's clearly false. (T&F = F)
Sugar is sweet OR grass is blue.
Yes, that's true. (T|F = T)
Sugar is sweet OR 1+1=2
Is the only one worth learning, computers think this is true. (T|T = T)
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:Whatever they're trying to teach you with truth tables, you can learn better with a little experimentation in an interactive environment.