Skip to content

Instantly share code, notes, and snippets.

@jasoares
Created May 17, 2012 03:14
Show Gist options
  • Select an option

  • Save jasoares/2715942 to your computer and use it in GitHub Desktop.

Select an option

Save jasoares/2715942 to your computer and use it in GitHub Desktop.
Ruby case statement tests
module TestUtils
# def self.case_with_colon_1_8_7(obj)
# return case obj
# when String: puts "String"; "String"
# when Symbol: puts "Symbol"; "Symbol"
# when Fixnum: puts "Fixnum"; "Fixnum"
# when Range : puts "Range" ; "Range"
# end
# end
def self.case_obj_class_error(obj)
return case obj
when String then "String"
when Symbol then "Symbol"
when Fixnum then "Fixnum"
end
end
def self.case_with_semicolon_both(obj)
return case obj
when String; puts "String"; "String"
when Symbol; puts "Symbol"; "Symbol"
when Fixnum; puts "Fixnum"; "Fixnum"
else print obj
end
end
def self.case_with_then_indented(obj)
return case obj
when String then puts "String"; "String"
when Symbol then puts "Symbol"; "Symbol"
when Fixnum then puts "Fixnum"; "Fixnum"
else obj
end
end
def self.case_with_then_unindented(obj)
return case obj
when String then puts "String"; "String"
when Symbol then puts "Symbol"; "Symbol"
when Symbol then puts "Fixnum"; "Fixnum"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment