Skip to content

Instantly share code, notes, and snippets.

@sumskyi
Created December 3, 2011 08:15
Show Gist options
  • Select an option

  • Save sumskyi/1426523 to your computer and use it in GitHub Desktop.

Select an option

Save sumskyi/1426523 to your computer and use it in GitHub Desktop.
hash driven conditional statements
#!/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