Class: Disk
- Inherits:
-
Object
- Object
- Disk
- Defined in:
- lib/Olib/character/disk.rb
Constant Summary collapse
- NOUNS =
%w{disk coffin}
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(obj) ⇒ Disk
constructor
A new instance of Disk.
- #method_missing(method, *args) ⇒ Object
- #to_container ⇒ Object
Constructor Details
#initialize(obj) ⇒ Disk
Returns a new instance of Disk.
27 28 29 30 31 32 |
# File 'lib/Olib/character/disk.rb', line 27 def initialize(obj) @id = obj.id @name = obj.name.split(" ").find do |word| word[0].upcase.eql?(word[0]) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
34 35 36 |
# File 'lib/Olib/character/disk.rb', line 34 def method_missing(method, *args) GameObj[@id].send(method, *args) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/Olib/character/disk.rb', line 25 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/Olib/character/disk.rb', line 25 def name @name end |
Class Method Details
.all ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/Olib/character/disk.rb', line 17 def self.all() (GameObj.loot || []).select do |item| is_disk?(item) end.map do |i| Disk.new(i) end end |
.find_by_name(name) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/Olib/character/disk.rb', line 9 def self.find_by_name(name) disk = GameObj.loot.find do |item| is_disk?(item) && item.name.include?(name) end return nil if disk.nil? Disk.new(disk) end |
.is_disk?(thing) ⇒ Boolean
5 6 7 |
# File 'lib/Olib/character/disk.rb', line 5 def self.is_disk?(thing) NOUNS.include?(thing.noun) end |