Created
August 1, 2012 22:14
-
-
Save haru01/3231159 to your computer and use it in GitHub Desktop.
if_then_else
This file contains hidden or 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
# -*- encoding: utf-8 -*- | |
class IfThenElse | |
def initialize(&block) | |
yield self | |
end | |
def exec | |
if @if.call | |
@then.call | |
else | |
@else.call | |
end | |
end | |
def if(&block) | |
@if = block | |
end | |
def then(&block) | |
@then = block | |
end | |
def else(&block) | |
@else = block | |
end | |
end | |
describe "IfThenElse#exec" do | |
subject do | |
IfThenElse.new do |c| | |
c.if { if_result } | |
c.then { 'then' } | |
c.else { 'else' } | |
end | |
end | |
context "if が trueの場合" do | |
let(:if_result) { true } | |
its(:exec) {should == 'then'} | |
end | |
context "if が falseの場合" do | |
let(:if_result) { false } | |
its(:exec) { should == 'else' } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment