Module: AdventureRL::Extensions::ArrayExtension
- Defined in:
- lib/AdventureRL/misc/extensions.rb
Overview
ARRAY
Instance Method Summary collapse
- #include_all?(*vals) ⇒ Boolean
- #include_any?(*vals) ⇒ Boolean
- #mean ⇒ Object
- #sort_by_array(*array) ⇒ Object
Instance Method Details
#include_all?(*vals) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/AdventureRL/misc/extensions.rb', line 25 def include_all? *vals return vals.all? do |val| next self.include? val end end |
#include_any?(*vals) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/AdventureRL/misc/extensions.rb', line 30 def include_any? *vals return vals.any? do |val| next self.include? val end end |
#mean ⇒ Object
46 47 48 |
# File 'lib/AdventureRL/misc/extensions.rb', line 46 def mean return (self.sum.to_f / self.size.to_f) end |
#sort_by_array(*array) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/AdventureRL/misc/extensions.rb', line 35 def sort_by_array *array array.flatten! return self.sort do |one, two| indexes = [ array.index(one), array.index(two) ] next (indexes[0] || Float::INFINITY) <=> (indexes[1] || Float::INFINITY) if (indexes.any?) next one <=> two end end |