Created
December 3, 2011 08:15
-
-
Save sumskyi/1426523 to your computer and use it in GitHub Desktop.
hash driven conditional statements
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
| #!/usr/bin/env ruby | |
| class A | |
| CONDITION = { | |
| nil => :a, | |
| false => :b, | |
| true => :c | |
| } | |
| def abc(val) | |
| self.send CONDITION[val] | |
| end | |
| private | |
| def a; puts 'a'; end | |
| def b; puts 'b'; end | |
| def c; puts 'c'; end | |
| end | |
| A.new.abc(nil) | |
| A.new.abc(false) | |
| A.new.abc(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment