Created
November 18, 2008 13:14
-
-
Save stefanoc/26120 to your computer and use it in GitHub Desktop.
This file contains 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
class Aif | |
def initialize(cond) | |
@cond = cond | |
end | |
def else | |
yield unless @cond | |
end | |
end | |
class Object | |
def aif(cond) | |
yield(cond) if cond | |
Aif.new(cond) | |
end | |
end | |
if $0 == __FILE__ | |
str = "foo bar" | |
aif(/(.+) (.+)/.match(str)) do |it| | |
puts "first element: #{it[1]}" | |
puts "second element: #{it[2]}" | |
end.else do | |
puts "no match" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment