not vs !, and vs &&

It’s always confusing when you have similar methods that have slightly different meaning. What’s the difference between not vs !, and and &&?

The difference between is subtle enough that it might not matter most of the time, but it might bite you in the ass one day. It doesn’t say which is which, this post gives the example of precedence order. But just by experimenting, you can see that it’s and, or, and not that form statements, which can’t be used in arguments

String.new(“hey” || “hello”) #=> “hey”
String.new(nil || “hello”) #=> “hello”
String.new(nil or “hello”) #=> error: can’t used statements in arguments
String.new((nil or “hello”)) #=> “hello” putting it in parens makes it ok, but ugly

tip!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s