Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

=== and the Case Equality Operator

In a case statement…

1
2
3
4
5
6
7
8
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

1
2
3
4
5
6
7
8
9
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

Comments