Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created March 22, 2012 20:45
Show Gist options
  • Save tcrayford/2164122 to your computer and use it in GitHub Desktop.
Save tcrayford/2164122 to your computer and use it in GitHub Desktop.
module Kernel
def an(value)
Thingy.new(value)
end
def none
Nothing.new
end
end
class Thingy < Struct.new(:value)
def has_value?
true
end
end
class Nothing
include Enumerable
def has_value?
false
end
def each
end
end
describe "with value" do
it "knows an object" do
an(1).value.should == 1
end
it "has a value" do
an(1).should have_value
end
it "enumerates an object" do
an(1).each do |value|
value.should == 1
end
end
it "can be mapped" do
an(1).map {|x| x}.should == [1]
end
end
describe "without value" do
it "doesn't enumerate no object" do
none.each do |value|
raise
end
end
it "knows no object" do
none.should_not have_value
end
it "maps to empty array" do
none.map {|x| x}.should == []
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment