Browse files

[ci skip] add example to AR#assign_attributes

  • Loading branch information...
1 parent 7063e25 commit c247370cae6ce681648b8272bf18562addea2353 @schneems schneems committed May 9, 2014
Showing with 10 additions and 0 deletions.
  1. +10 −0 activerecord/lib/active_record/attribute_assignment.rb
View
10 activerecord/lib/active_record/attribute_assignment.rb
@@ -11,6 +11,16 @@ module AttributeAssignment
# If the passed hash responds to <tt>permitted?</tt> method and the return value
# of this method is +false+ an <tt>ActiveModel::ForbiddenAttributesError</tt>
# exception is raised.
+ #
+ # Example:
+ #
+ # cat = Cat.new(name: "Gorby", status: "yawning")
+ # cat.attributes # => {"name" => "Gorby", "status" => "yawning"}
+ # cat.assign_attributes(status: "sleeping")
+ # cat.attributes # => {"name" => "Gorby", "status" => "sleeping"}
+ #
+ # New attributes will be persisted to database when object is saved.
+ # <tt>attributes =</tt> is an alias.
def assign_attributes(new_attributes)
if !new_attributes.respond_to?(:stringify_keys)
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."

0 comments on commit c247370

Please sign in to comment.