Created
May 17, 2012 03:14
-
-
Save jasoares/2715942 to your computer and use it in GitHub Desktop.
Ruby case statement tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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