method

define_attr_method

Importance_0
v3.2.13 - Show latest stable - 0 notes - Class: ActiveModel::AttributeMethods::ClassMethods
define_attr_method(name, value=nil, deprecation_warning = true, &block) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activemodel/lib/active_model/attribute_methods.rb, line 69 def define_attr_method(name, value=nil, deprecation_warning = true, &block) #:nodoc: # This deprecation_warning param is for internal use so that we can silence # the warning from Active Record, because we are implementing more specific # messages there instead. # # It doesn't apply to the original_#{name} method as we want to warn if # people are calling that regardless. if deprecation_warning ActiveSupport::Deprecation.warn("define_attr_method is deprecated and will be removed without replacement.") end sing = singleton_class sing.class_eval remove_possible_method :'original_#{name}' remove_possible_method :'_original_#{name}' alias_method :'_original_#{name}', :'#{name}' define_method :'original_#{name}' do ActiveSupport::Deprecation.warn( "This method is generated by ActiveModel::AttributeMethods::ClassMethods#define_attr_method, " \ "which is deprecated and will be removed." ) send(:'_original_#{name}') end, __FILE__, __LINE__ + 1 if block_given? sing.send :define_method, name, &block else # If we can compile the method name, do it. Otherwise use define_method. # This is an important *optimization*, please don't change it. define_method # has slower dispatch and consumes more memory. if name =~ NAME_COMPILABLE_REGEXP sing.class_eval def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end, __FILE__, __LINE__ + 1 else value = value.to_s if value sing.send(:define_method, name) { value } end end end
Register or log in to add new notes.