Permalink
Browse files

Improve Lazy

  • Loading branch information...
1 parent 32b29ef commit 57c702ea8ef5e46e0af6e3bbfc5592ea696e2aca @dag committed May 31, 2008
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/amazing/lazy.rb
View
@@ -14,18 +14,21 @@
module Amazing
class Lazy
+ undef_method :to_s
+ undef_method :inspect
+
def initialize(&block)
- @block = block
+ @lazy_block = block
end
- def to_s
- @value ||= @block.call.to_s
+ def method_missing(name, *args, &block)
+ __value__.__send__(name, *args, &block)
end
- alias inspect to_s
+ private
- def method_missing(name, *args, &block)
- to_s.__send__(name, *args, &block)
+ def __value__
+ @lazy_value ||= @lazy_block.call
end
end
end

0 comments on commit 57c702e

Please sign in to comment.