Class: NPCS
Overview
a collection for managing all of the npcs in a room
Constant Summary collapse
- ALL =
-> npc { true }
Instance Attribute Summary collapse
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(&predicate) ⇒ NPCS
constructor
A new instance of NPCS.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(&predicate) ⇒ NPCS
Returns a new instance of NPCS.
11 12 13 |
# File 'lib/Olib/npcs/npcs.rb', line 11 def initialize(&predicate) @predicate = predicate end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/Olib/npcs/npcs.rb', line 25 def method_missing(method, *args) if to_a.respond_to?(method) to_a.send(method, *args) else super(method, *args) end end |
Instance Attribute Details
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
9 10 11 |
# File 'lib/Olib/npcs/npcs.rb', line 9 def predicate @predicate end |
Class Method Details
Instance Method Details
#each ⇒ Object
15 16 17 18 19 |
# File 'lib/Olib/npcs/npcs.rb', line 15 def each() GameObj.npcs.to_a.map do |obj| NPC.new(obj) end .select(&@predicate) .each do |npc| yield(npc) unless npc..include?(:aggressive) end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
21 22 23 |
# File 'lib/Olib/npcs/npcs.rb', line 21 def respond_to_missing?(method, include_private = false) to_a.respond_to?(method) or super end |