method
define_attr_method
v3.2.1 -
Show latest stable
-
0 notes -
Class: ActiveModel::AttributeMethods::ClassMethods
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (-38)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
define_attr_method(name, value=nil, deprecation_warning = true, &block)
public
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