instance method
new
Ruby on Rails 4.2.9
Since v4.0.13Signature
new(*args, &block)
Determines if one of the attributes passed in is the inheritance column, and if the inheritance column is attr accessible, it initializes an instance of the given subclass instead of the base class.
Parameters
-
argsrest -
blockblock
Source
# File activerecord/lib/active_record/inheritance.rb, line 48
def new(*args, &block)
if abstract_class? || self == Base
raise NotImplementedError, "#{self} is an abstract class and cannot be instantiated."
end
attrs = args.first
if subclass_from_attributes?(attrs)
subclass = subclass_from_attributes(attrs)
end
if subclass
subclass.new(*args, &block)
else
super
end
end
Defined in activerecord/lib/active_record/inheritance.rb line 48
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Inheritance::ClassMethods