=== case equality operator

In a case statement…

case number

when 5

#some code

when 3

#more code

else

#something else

end

Behind the scenes 5 is being compared to number with the === operator, so 5 === number, 3 === number, etc

 

several = Proc.new { |number| number > 3 && number < 8 }

none = Proc.new { |number| number == 0 }

case number

when several

puts “several”

when none

puts “none”

end

#In this case the several proc is being run and if it returns true it runs the puts –> this abstracts everything away

 

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