Class: PirateGame::LogBook
- Inherits:
-
Object
- Object
- PirateGame::LogBook
- Includes:
- Enumerable
- Defined in:
- lib/pirate_game/log_book.rb
Instance Method Summary collapse
- #add(entry, author = 'unknown') ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(size = 10) ⇒ LogBook
constructor
A new instance of LogBook.
- #length ⇒ Object (also: #size)
Constructor Details
#initialize(size = 10) ⇒ LogBook
Returns a new instance of LogBook.
7 8 9 10 11 |
# File 'lib/pirate_game/log_book.rb', line 7 def initialize size = 10 @mutex = Mutex.new @log_book = [] @size = size end |
Instance Method Details
#add(entry, author = 'unknown') ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pirate_game/log_book.rb', line 13 def add entry, = 'unknown' @mutex.synchronize do @log_book << [entry, ] @log_book.shift if @log_book.size > @size end end |
#each ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/pirate_game/log_book.rb', line 21 def each return enum_for __method__ unless block_given? @log_book.each do |(entry, )| yield [entry, ] end end |
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/pirate_game/log_book.rb', line 29 def empty? @log_book.empty? end |
#length ⇒ Object Also known as: size
33 34 35 |
# File 'lib/pirate_game/log_book.rb', line 33 def length @log_book.length end |