Class: CraftingTable::Item
- Inherits:
-
Object
- Object
- CraftingTable::Item
- Defined in:
- lib/crafting_table/item.rb
Overview
A class representing a single item. An item, in this case, can be any block, tool, loot etc.
Instance Attribute Summary collapse
- #damage_value ⇒ Object readonly
- #item_id ⇒ Object readonly
- #name ⇒ Object readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare two items for equality.
-
#hash ⇒ Integer
Return reasonable hash value of this item.
-
#identifier ⇒ Array<Integer>
Return a unique identifier of this item.
-
#initialize(name, item_id, damage_value = 0) ⇒ Item
constructor
Create a new Item.
Constructor Details
#initialize(name, item_id, damage_value = 0) ⇒ Item
Create a new Item.
24 25 26 |
# File 'lib/crafting_table/item.rb', line 24 def initialize(name, item_id, damage_value = 0) @name, @item_id, @damage_value = name, item_id, damage_value end |
Instance Attribute Details
#damage_value ⇒ Object (readonly)
11 12 13 |
# File 'lib/crafting_table/item.rb', line 11 def damage_value @damage_value end |
#item_id ⇒ Object (readonly)
11 12 13 |
# File 'lib/crafting_table/item.rb', line 11 def item_id @item_id end |
#name ⇒ Object (readonly)
11 12 13 |
# File 'lib/crafting_table/item.rb', line 11 def name @name end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare two items for equality.
Two items are considered equal, if their name, item ID and damage value are equal.
34 35 36 |
# File 'lib/crafting_table/item.rb', line 34 def ==(other) name == other.name && item_id == other.item_id && damage_value == other.damage_value end |
#hash ⇒ Integer
Return reasonable hash value of this item.
45 46 47 |
# File 'lib/crafting_table/item.rb', line 45 def hash [name, item_id, damage_value].hash end |
#identifier ⇒ Array<Integer>
Return a unique identifier of this item. The identifier is an array, containing its ID and damage value
55 56 57 |
# File 'lib/crafting_table/item.rb', line 55 def identifier [item_id, damage_value] end |