Module CoreEx::Module::AttrOnce
In: lib/core_ex/module/attr_once.rb

Methods

attr_once  

Public Instance methods

You can use this method as you use attr_reader. Must be used only with immutable object.

This method is imported from the Date implementation. It provides a way to compute only once the value of getter. Basically, the first time, the getter is used, its result is computed and stored in an attribute with the same name. The second times only the attribute is returned.

[Source]

# File lib/core_ex/module/attr_once.rb, line 19
      def attr_once(*ids)
        for id in ids
          module_eval "alias_method :__\#{id.to_i}__, :\#{id.to_s}\nprivate :__\#{id.to_i}__\ndef \#{id.to_s}(*args, &block)\nif defined? @__\#{id.to_i}__\n@__\#{id.to_i}__\nelsif ! self.frozen?\n@__\#{id.to_i}__ ||= __\#{id.to_i}__(*args, &block)\nelse\n__\#{id.to_i}__(*args, &block)\nend\nend\n", __FILE__, __LINE__
        end
      end

[Validate]