Permalink
Browse files

On second thought, #unwrap shouldn't take a block. Don't make it so p…

…owerful.
  • Loading branch information...
1 parent 2410bd4 commit 10554fbaa1f911313522c3e42c074bd1c47f66f7 @mike-burns mike-burns committed Jul 29, 2011
Showing with 9 additions and 17 deletions.
  1. +9 −9 lib/wrapped/types.rb
  2. +0 −8 spec/wrapped_spec.rb
View
@@ -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)
@@ -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?
View
@@ -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

0 comments on commit 10554fb

Please sign in to comment.