Class: Loot

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/Olib/loot.rb

Constant Summary collapse

ALL =
-> item { true }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#predicateObject (readonly)

Returns the value of attribute predicate.



6
7
8
# File 'lib/Olib/loot.rb', line 6

def predicate
  @predicate
end

Class Method Details

.method_missing(method, *args, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/Olib/loot.rb', line 33

def self.method_missing(method, *args, &block)
  if respond_to?(method)
    Loot.new.send(method, *args, &block)
  else
    super(method, *args, &block)
  end
end

.respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/Olib/loot.rb', line 41

def self.respond_to?(method)
  return super(method) unless Loot.new.respond_to?(method)
  return true
end

Instance Method Details

#eachObject



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

Returns:

  • (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