Class: Loot
Constant Summary collapse
- ALL =
-> item { 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) ⇒ Loot
constructor
A new instance of Loot.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(&predicate) ⇒ Loot
Returns a new instance of Loot.
8 9 10 |
# File 'lib/Olib/loot.rb', line 8 def initialize(&predicate) @predicate = predicate end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/Olib/loot.rb', line 24 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.
6 7 8 |
# File 'lib/Olib/loot.rb', line 6 def predicate @predicate end |
Class Method Details
Instance Method Details
#each ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/Olib/loot.rb', line 12 def each() GameObj.loot.to_a .reject(&Where[noun: "disk"]) .map do |obj| Item.new(obj) end .select(&@predicate) .each do |item| yield(item) end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
20 21 22 |
# File 'lib/Olib/loot.rb', line 20 def respond_to_missing?(method, include_private = false) to_a.respond_to?(method) or super end |