Created
July 28, 2014 19:20
-
-
Save mboeh/8b4fcba54d44baa016b9 to your computer and use it in GitHub Desktop.
cnd.rb
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
alias λ proc | |
alias _l proc | |
class Object | |
def cnd(t:λ{},f:λ{}) | |
t[] | |
end | |
end | |
class NilClass | |
def cnd(t:λ{},f:λ{}) | |
f[] | |
end | |
end | |
class FalseClass | |
def cnd(t:λ{},f:λ{}) | |
f[] | |
end | |
end | |
if $0 == __FILE__ | |
require 'minitest/autorun' | |
Class.new(Minitest::Test) do | |
def test_cnd | |
1.nonzero?.cnd t: λ{ assert "it's nonzero" }, f: λ{ fail "it's zero" } | |
end | |
def test_omit | |
1.nonzero?.cnd f: _l{ fail "it's zero" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment