Why do I get "thumbs down"?
p = Post.new
case p.class
when Post
"Thumbs up"
else
"Thumbs down"
end
Why do I get "thumbs down"?
p = Post.new
case p.class
when Post
"Thumbs up"
else
"Thumbs down"
end
You don't need to check classes specifically. Check instances, this is how case works.
p = Post.new
case p
when Post
"Thumbs up"
else
"Thumbs down"
end
"I have this thing p
, what might it be? Is it a Post or maybe a string that conforms to this regex? Or some another thing?"
More info on threequals operator, the power behind ruby's case expression: https://stackoverflow.com/a/4528453/125816