Module: ParaDice::Utility
- Defined in:
- lib/para_dice/utility.rb
Overview
provides utility methods used by other parts of ParaDice.
Class Method Summary collapse
-
.from_summary(summary) ⇒ Array<Object>
from_summary creates an array and populates with a number of each key equal to the value for that key.
-
.module_from(name, namespace = nil) ⇒ false, ...
Generate a Class or Module from a representation for the class.
-
.to_summary(arr) ⇒ Hash
to_summary creates a hash and populates it with uniq elements of the array, and the count of how many there are.
Class Method Details
.from_summary(summary) ⇒ Array<Object>
from_summary creates an array and populates with a number of each key
equal to the value for that key
48 49 50 |
# File 'lib/para_dice/utility.rb', line 48 def self.from_summary(summary) summary.each_pair.map { |e, c| Array.new(c) { e } }.flatten end |
.module_from(name, namespace = nil) ⇒ false, ...
Generate a Class or Module from a representation for the class.
24 25 26 27 28 |
# File 'lib/para_dice/utility.rb', line 24 def self.module_from(name, namespace = nil) return name if name.is_a? Module return false if name.empty? self.module_from_top(name) || self.module_from_namespace(name, namespace) end |
.to_summary(arr) ⇒ Hash
to_summary creates a hash and populates it with uniq elements of the
array, and the count of how many there are
37 38 39 |
# File 'lib/para_dice/utility.rb', line 37 def self.to_summary(arr) arr.reduce(Hash.new(0)) { |h, e| h[e] += 1; h } end |