Sha256: c0355eccc4a694f9d5749df0997bd99a3d1e0d06626bb02ca0f6389aa1dd7332

Contents?: true

Size: 476 Bytes

Versions: 2

Compression:

Stored size: 476 Bytes

Contents

module Nasty
  class Lazy 
    def initialize(factory = ->(key) { key.new }, *arguments)
      @factory = factory
      @arguments = arguments
    end

    def method_missing(name, *args, &block)
      @target ||= @factory.call(*@arguments)
      @target.send(name, args, &block)
    end

    class << self
      def bind_resolver(&block)
        @@factory = block
      end

      def load(key, factory = @@factory)
        Lazy.new(factory, key)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nasty-0.0.1388166944 lib/nasty/lazy.rb
nasty-0.0.1388166636 lib/nasty/lazy.rb