Ruby has no failure for case.
One alternative is a series of statements ifthat use a method ===that is used caseto compare elements within.
has_matched? = false
if '2' === var
has_matched? = true
end
if '3' === var
has_matched? = true
end
if something_else === var
has_matched? = true
end
if !has_matched?
end
.
matches?, . , , ( , var), else_do, , @has_matched?.
Edit:
=== , , . , "" . :
class String
def ===(other_str)
self.strip[0, other_str.length].downcase == other_str.downcase
end
end
class Array
def ===(str)
self.any? {|elem| elem.include?(str)}
end
end
class Fixnum
def ===(str)
self == str.to_i
end
end
, Ruby case var, === , var.