Skip to content

Commit

Permalink
Add code example for include option of AM::Serialization#serializable…
Browse files Browse the repository at this point in the history
…_hash
  • Loading branch information
radanskoric authored and rafaelfranca committed Jun 9, 2015
1 parent 1a82e20 commit 3d949f3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion activemodel/lib/active_model/serialization.rb
Expand Up @@ -72,10 +72,20 @@ module ActiveModel
module Serialization
# Returns a serialized hash of your object.
#
# class Address
# include ActiveModel::Serialization
#
# attr_accessor :city, :street
#
# def attributes
# {'city' => nil, 'street' => nil}
# end
# end
#
# class Person
# include ActiveModel::Serialization
#
# attr_accessor :name, :age
# attr_accessor :name, :age, :address
#
# def attributes
# {'name' => nil, 'age' => nil}
Expand All @@ -89,6 +99,9 @@ module Serialization
# person = Person.new
# person.name = 'bob'
# person.age = 22
# person.address = Address.new
# person.address.city = 'New York'
# person.address.street = 'Main St'
# person.serializable_hash # => {"name"=>"bob", "age"=>22}
# person.serializable_hash(only: :name) # => {"name"=>"bob"}
# person.serializable_hash(except: :name) # => {"age"=>22}
Expand Down

0 comments on commit 3d949f3

Please sign in to comment.