Class: BOO::Book
- Inherits:
-
Object
- Object
- BOO::Book
- Defined in:
- lib/boo.rb
Instance Attribute Summary collapse
-
#chapters ⇒ Object
Returns the value of attribute chapters.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#testament ⇒ Object
Returns the value of attribute testament.
Instance Method Summary collapse
- #<<(chapter) ⇒ Object
- #[](number) ⇒ Object
-
#initialize(name, number) ⇒ Book
constructor
A new instance of Book.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
#initialize(name, number) ⇒ Book
Returns a new instance of Book.
23 24 25 26 27 |
# File 'lib/boo.rb', line 23 def initialize(name, number) self.name = name self.number = number self.chapters = {} end |
Instance Attribute Details
#chapters ⇒ Object
Returns the value of attribute chapters.
22 23 24 |
# File 'lib/boo.rb', line 22 def chapters @chapters end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/boo.rb', line 22 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
22 23 24 |
# File 'lib/boo.rb', line 22 def number @number end |
#testament ⇒ Object
Returns the value of attribute testament.
22 23 24 |
# File 'lib/boo.rb', line 22 def testament @testament end |
Instance Method Details
#<<(chapter) ⇒ Object
31 32 33 |
# File 'lib/boo.rb', line 31 def << (chapter) self.chapters[chapter.number] = chapter end |
#[](number) ⇒ Object
28 29 30 |
# File 'lib/boo.rb', line 28 def [](number) self.chapters[number] end |
#inspect ⇒ Object Also known as: to_s
34 35 36 |
# File 'lib/boo.rb', line 34 def inspect "#{self.number} - #{self.name} (#{self.chapters.length} chapters)." end |