Skip to content

Instantly share code, notes, and snippets.

@mboeh
Created July 28, 2014 19:20
Show Gist options
  • Save mboeh/8b4fcba54d44baa016b9 to your computer and use it in GitHub Desktop.
Save mboeh/8b4fcba54d44baa016b9 to your computer and use it in GitHub Desktop.
cnd.rb
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