stuff Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what does !! mean?

A

Preceding a truthy object with a single bang ! will return false and preceding it with a double bang !! will return true:

a = “hello”
!a # => false
!!a # => true

The converse is true for falsey objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

puts vs p

A
For example:
> puts "Ruby Is Cool"
Ruby Is Cool
> p "Ruby Is Cool"
"Ruby Is Cool"

What is p useful for?

Debugging.

When you’re looking for things like (normally invisible) newline characters, or you want to make sure some value is correct, then you use p.

Another difference:

puts always returns nil
p returns the object you pass to it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

truthy

A

Remember this rule: everything in Ruby is considered “truthy” except for false and nil.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly