Class: Car

Inherits:
Object show all
Defined in:
lib/car.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#makeObject

Returns the value of attribute make.



2
3
4
# File 'lib/car.rb', line 2

def make
  @make
end

#modelObject

Returns the value of attribute model.



2
3
4
# File 'lib/car.rb', line 2

def model
  @model
end

#yearObject

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