Class: TCLog::Game::PlayerArray

Inherits:
Hash
  • Object
show all
Defined in:
lib/tclog.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PlayerArray

:nodoc:



11
12
13
14
# File 'lib/tclog.rb', line 11

def initialize(*args) # :nodoc:
  @ary = []
  super *args
end

Instance Method Details

#<<(player) ⇒ Object

player

TCLog::Player object.

Add Player.



44
45
46
47
48
# File 'lib/tclog.rb', line 44

def <<(player)
  @ary << player.name unless @ary.include?(player.name)
  self[player.name] = player
  self
end

#[](x) ⇒ Object

x

String or Integer. String finds player from name, Integer finds player from index.

Get Player object.



21
22
23
24
25
26
27
# File 'lib/tclog.rb', line 21

def [](x)
  if x.kind_of?(Integer)
    self[@ary[x]] if @ary[x]
  else
    super x
  end
end

#[]=(a, b) ⇒ Object

a

Player’s name.

b

TCLog::Player object.

Add Player with name.


35
36
37
38
# File 'lib/tclog.rb', line 35

def []=(a,b)
  @ary << a unless @ary.include?(a)
  super a,b
end

#eachObject

yield each player



51
52
53
54
55
# File 'lib/tclog.rb', line 51

def each # :yield: player
  @ary.each do |name|
    yield self[name]
  end
end

#inspectObject

:nodoc:



57
58
59
60
61
# File 'lib/tclog.rb', line 57

def inspect # :nodoc:
  @ary.map do |name|
    self[name]
  end
end