Skip to content

Commit

Permalink
On second thought, #unwrap shouldn't take a block. Don't make it so p…
Browse files Browse the repository at this point in the history
…owerful.
  • Loading branch information
mike-burns committed Jul 29, 2011
1 parent 2410bd4 commit 10554fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
18 changes: 9 additions & 9 deletions lib/wrapped/types.rb
Expand Up @@ -5,8 +5,12 @@ def initialize(value)
@value = value
end

def unwrap_or(_, &block)
unwrap(&block)
def unwrap_or(_)
if block_given?
yield unwrap
else
unwrap
end
end

def present(&block)
Expand All @@ -18,17 +22,13 @@ def blank(&ignored)
self
end

def each(&block)
unwrap(&block)
def each
yield unwrap if block_given?
[unwrap]
end

def unwrap
if block_given?
yield @value
else
@value
end
@value
end

def present?
Expand Down
8 changes: 0 additions & 8 deletions spec/wrapped_spec.rb
Expand Up @@ -26,14 +26,6 @@
it 'raises an exception when called on the wrapped nil' do
expect { nothing.unwrap }.to raise_error(IndexError)
end

it 'produces the value of the block for a wrapped object' do
just.unwrap {|n| n+1}.should == value+1
end

it 'raises an exception when called on the wrapped nil, even with a block' do
expect { nothing.unwrap { 2 } }.to raise_error(IndexError)
end
end

describe Wrapped, 'callbacks' do
Expand Down

0 comments on commit 10554fb

Please sign in to comment.