Created
July 19, 2012 07:39
-
-
Save nakamuray/3141393 to your computer and use it in GitHub Desktop.
if
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
def myif(b, then_block, else_block) | |
h = Hash.new(then_block) | |
h[false] = else_block | |
h[nil] = else_block | |
return h[b].call() | |
end | |
def mythen(&block) | |
return block | |
end | |
def myelse(&block) | |
return block | |
end | |
puts | |
puts "true" | |
puts "----" | |
myif true, mythen { | |
puts "hello world" | |
puts "hello world" | |
}, myelse { | |
puts "hello ruby" | |
} | |
puts | |
puts "false" | |
puts "-----" | |
myif false, mythen { | |
puts "hello world" | |
puts "hello world" | |
}, myelse { | |
puts "hello ruby" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment