Class: Car
Instance Attribute Summary collapse
-
#make ⇒ Object
Returns the value of attribute make.
-
#model ⇒ Object
Returns the value of attribute model.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
-
#initialize(make, model, year) ⇒ Car
constructor
A new instance of Car.
- #to_xml(wax) ⇒ Object
Constructor Details
#initialize(make, model, year) ⇒ Car
Returns a new instance of Car.
4 5 6 |
# File 'lib/car.rb', line 4 def initialize(make, model, year) @make, @model, @year = make, model, year end |
Instance Attribute Details
#make ⇒ Object
Returns the value of attribute make.
2 3 4 |
# File 'lib/car.rb', line 2 def make @make end |
#model ⇒ Object
Returns the value of attribute model.
2 3 4 |
# File 'lib/car.rb', line 2 def model @model end |
#year ⇒ Object
Returns the value of attribute year.
2 3 4 |
# File 'lib/car.rb', line 2 def year @year end |
Instance Method Details
#to_xml(wax) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/car.rb', line 8 def to_xml(wax) # Chaining approach #wax.start('car').attr('year', @year). # child('make', @make). # child('model', @model). # end! # Non-chaining approach # Put the current object in a local variable # so it can be accessed in the block passed to the write method. car = self wax.write do start 'car' attr 'year', car.year child 'make', car.make child 'model', car.model end! end end |