instance method
define_attribute_method
Ruby on Rails 3.1.12
Since v3.1.12Signature
define_attribute_method(attr_name)
No documentation comment.
Parameters
-
attr_namereq
Source
# File activemodel/lib/active_model/attribute_methods.rb, line 285
def define_attribute_method(attr_name)
attribute_method_matchers.each do |matcher|
unless instance_method_already_implemented?(matcher.method_name(attr_name))
generate_method = "define_method_#{matcher.prefix}attribute#{matcher.suffix}"
if respond_to?(generate_method, true)
send(generate_method, attr_name)
else
method_name = matcher.method_name(attr_name)
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
if method_defined?('#{method_name}')
undef :'#{method_name}'
end
RUBY
if method_name.to_s =~ COMPILABLE_REGEXP
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method_name}(*args)
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)
end
RUBY
else
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
define_method('#{method_name}') do |*args|
send('#{matcher.method_missing_target}', '#{attr_name}', *args)
end
RUBY
end
end
end
end
end
Defined in activemodel/lib/active_model/attribute_methods.rb line 285
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::AttributeMethods::ClassMethods