Module: Once::ClassMethods

Defined in:
lib/chem/utils/once.rb

Instance Method Summary collapse

Instance Method Details

#once(*ids) ⇒ Object

:nodoc:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chem/utils/once.rb', line 9

def once(*ids) # :nodoc:
  for id in ids
	module_eval <<-"end;", __FILE__, __LINE__
    alias_method :__#{id.to_i}__, :#{id.to_s}
    private :__#{id.to_i}__
    def #{id.to_s}(*args, &block)
      if defined? @__#{id.to_i}__
        @__#{id.to_i}__
      elsif ! self.frozen?
        @__#{id.to_i}__ ||= __#{id.to_i}__(*args, &block)
      else
        __#{id.to_i}__(*args, &block)
      end
    end
  end;
  end
end