Class: Pktool::Party
- Inherits:
-
Object
- Object
- Pktool::Party
- Defined in:
- lib/party.rb
Constant Summary collapse
- @@json_path =
"data/user/party.json"
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #add(pokemon) ⇒ Object
- #delete(id) ⇒ Object
-
#initialize ⇒ Party
constructor
A new instance of Party.
- #save ⇒ Object
- #update(id, pokemon) ⇒ Object
Constructor Details
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
7 8 9 |
# File 'lib/party.rb', line 7 def list @list end |
Instance Method Details
#[](id) ⇒ Object
28 29 30 |
# File 'lib/party.rb', line 28 def [](id) return @list[id] end |
#add(pokemon) ⇒ Object
24 25 26 |
# File 'lib/party.rb', line 24 def add(pokemon) @list.push(pokemon) end |
#delete(id) ⇒ Object
32 33 34 |
# File 'lib/party.rb', line 32 def delete(id) @list.delete_at(id) end |
#save ⇒ Object
18 19 20 21 22 |
# File 'lib/party.rb', line 18 def save open(@@json_path, 'w') do |io| JSON.dump(@list.map{|p| p.to_h}, io) end end |
#update(id, pokemon) ⇒ Object
36 37 38 |
# File 'lib/party.rb', line 36 def update(id, pokemon) $list[id] = pokemon end |