Methods

Constants

METHOD_CACHES = Hash.new { |h, k| h[k] = Module.new }
 

Class Public methods

new(namespace)

# File activemodel/lib/active_model/attribute_methods.rb, line 365
def initialize(namespace)
  @cache = METHOD_CACHES[namespace]
  @sources = []
  @methods = {}
end

Instance Public methods

apply(owner, path, line)

# File activemodel/lib/active_model/attribute_methods.rb, line 382
def apply(owner, path, line)
  unless @sources.empty?
    @cache.module_eval("# frozen_string_literal: true\n" + @sources.join(";"), path, line)
  end
  @methods.each do |name, as|
    owner.define_method(name, @cache.instance_method(as))
  end
end

define_cached_method(name, as: name)

# File activemodel/lib/active_model/attribute_methods.rb, line 371
def define_cached_method(name, as: name)
  name = name.to_sym
  as = as.to_sym
  @methods.fetch(name) do
    unless @cache.method_defined?(as)
      yield @sources
    end
    @methods[name] = as
  end
end