Sha256: 7642f230c92f997b15438bdae4b7c4cffd39e0ed09ed63970c94d9a9423d3925

Contents?: true

Size: 612 Bytes

Versions: 1

Compression:

Stored size: 612 Bytes

Contents

class Object
  def lazy(&block)
    Lazy.new(self, &block)
  end
end

class Lazy < (::RUBY_VERSION < '1.9') ? Object : BasicObject
  undef_method(*(instance_methods - %w/__id__ __send__ respond_to? debugger/)) if ::RUBY_VERSION < '1.9'

  def initialize(obj, &block)
    @obj, @block = obj, block
    @args = @done = nil
  end

  def method_missing(*args, &block)
    unless @done
      if !@args && !@block
        @args, @block = args, @block
        return self
      end

      @res = @args ?  @obj.send(*@args, &@block) : @block.call(@obj)
      @done = true
    end

    @res.send(*args, &block)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lazyeval-0.0.3 lib/lazyeval.rb