Class: DelayedProc

Inherits:
Proc show all
Defined in:
lib/mixins/delayed.rb

Overview

Allow delayed actions to be describe and run only after

the initialize block has completed.

Usage:
  class Test
    include Delayed

    def initialize(&block)
      instance_eval &block if block
      loaded = true

      run_after_loaded do |b|
        instance_eval &b if b
      end

    end
  end

Instance Method Summary collapse

Methods inherited from Proc

#code, #proc_info, #source, #source_file, #source_line_number

Constructor Details

#initialize(proxy, &block) ⇒ DelayedProc

Returns a new instance of DelayedProc.



22
23
24
25
# File 'lib/mixins/delayed.rb', line 22

def initialize(proxy, &block)
  @proxy = proxy
  @proc = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &block) ⇒ Object



29
30
31
# File 'lib/mixins/delayed.rb', line 29

def method_missing(m,*a,&block)
  result.send(m,*a,&block)
end

Instance Method Details

#resultObject



26
27
28
# File 'lib/mixins/delayed.rb', line 26

def result
  @result ||= @proc.call
end