module Nuggets::Module::LazyAttrMixin

Public Instance Methods

lazy_accessor(name, options = {}, &block) click to toggle source
# File lib/nuggets/module/lazy_attr_mixin.rb, line 33
def lazy_accessor(name, options = {}, &block)
  attr_writer(attr = lazy_name(name, options))
  lazy_reader(name, options, attr, &block)
end
lazy_attr(name, options = {}, attr = lazy_name(name, options), &block)
Alias for: lazy_reader
lazy_reader(name, options = {}, attr = lazy_name(name, options), &block) click to toggle source
# File lib/nuggets/module/lazy_attr_mixin.rb, line 38
def lazy_reader(name, options = {}, attr = lazy_name(name, options), &block)
  define_method(name) { lazy_attr(attr,
    options.fetch(:freeze, true), &block) }
end
Also aliased as: lazy_attr

Private Instance Methods

lazy_name(name, options) click to toggle source
# File lib/nuggets/module/lazy_attr_mixin.rb, line 47
def lazy_name(name, options)
  options.fetch(:name) { name.to_s.sub(/\?\z/, '_p') }
end