Skip to content

Instantly share code, notes, and snippets.

@haru01
Created August 1, 2012 22:14
Show Gist options
  • Save haru01/3231159 to your computer and use it in GitHub Desktop.
Save haru01/3231159 to your computer and use it in GitHub Desktop.
if_then_else
# -*- 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