Update ActiveModel::Attributes examples in docs

This commit is contained in:
Usman 2022-02-11 01:19:49 +05:00
parent 0f3642596f
commit 3324cbdff5
9 changed files with 30 additions and 11 deletions

View File

@ -23,7 +23,8 @@ module ActiveModel
# attribute :active, :boolean, default: true
# end
#
# person = Person.new(name: "Volmer")
# person = Person.new
# person.name = "Volmer"
#
# person.name # => "Volmer"
# person.active # => true
@ -50,7 +51,8 @@ module ActiveModel
# attribute :active, :boolean, default: true
# end
#
# person = Person.new(name: "Volmer")
# person = Person.new
# person.name = "Volmer"
#
# person.name # => "Volmer"
# person.active # => true
@ -132,7 +134,10 @@ module ActiveModel
# attribute :age, :integer
# end
#
# person = Person.new(name: "Francesco", age: 22)
# person = Person.new
# person.name = "Francesco"
# person.age = 22
#
# person.attributes # => { "name" => "Francesco", "age" => 22}
def attributes
@attributes.to_hash

View File

@ -13,7 +13,9 @@ module ActiveModel
# attribute :id, :big_integer
# end
#
# person = Person.new(id: "18_000_000_000")
# person = Person.new
# person.id = "18_000_000_000"
#
# person.id # => 18000000000
#
# All casting and serialization are performed in the same way as the

View File

@ -11,7 +11,8 @@ module ActiveModel
# attribute :birthday, :date
# end
#
# person = Person.new(birthday: "1989-07-13")
# person = Person.new
# person.birthday = "1989-07-13"
#
# person.birthday.class # => Date
# person.birthday.year # => 1989

View File

@ -11,7 +11,8 @@ module ActiveModel
# attribute :start, :datetime
# end
#
# event = Event.new(start: "Wed, 04 Sep 2013 03:00:00 EAT")
# event = Event.new
# event.start = "Wed, 04 Sep 2013 03:00:00 EAT"
#
# event.start.class # => Time
# event.start.year # => 2013

View File

@ -13,7 +13,9 @@ module ActiveModel
# attribute :weight, :decimal
# end
#
# bag = BagOfCoffee.new(weight: "0.0001")
# bag = BagOfCoffee.new
# bag.weight = "0.0001"
#
# bag.weight # => 0.1e-3
#
# Numeric instances are converted to BigDecimal instances. Any other objects

View File

@ -13,7 +13,9 @@ module ActiveModel
# attribute :weight, :float
# end
#
# bag = BagOfCoffee.new(weight: "0.25")
# bag = BagOfCoffee.new
# bag.weight = "0.25"
#
# bag.weight # => 0.25
#
# Values are coerced to their float representation using their +to_f+

View File

@ -13,6 +13,7 @@ module ActiveModel
#
# person = Person.new
# person.name = 1
#
# person.name # => "1"
# person.name.frozen? # => true
#
@ -27,7 +28,9 @@ module ActiveModel
# attribute :active, :immutable_string, true: "aye", false: "nay"
# end
#
# person = Person.new(active: true)
# person = Person.new
# person.active = true
#
# person.active # => "aye"
class ImmutableString < Value
def initialize(**args)

View File

@ -11,7 +11,9 @@ module ActiveModel
# attribute :age, :integer
# end
#
# person = Person.new(age: "18")
# person = Person.new
# person.age = "18"
#
# person.age # => 18
#
# Values are cast using their +to_i+ method, if it exists. If it does not

View File

@ -11,7 +11,8 @@ module ActiveModel
# attribute :start, :time
# end
#
# event = Event.new(start: "2022-02-18T13:15:00-05:00")
# event = Event.new
# event.start = "2022-02-18T13:15:00-05:00"
#
# event.start.class # => Time
# event.start.year # => 2022