Module: Supplejack::Util
- Defined in:
- lib/supplejack/util.rb
Class Method Summary collapse
-
.array(object) ⇒ Object
Return a array no matter what.
-
.deep_merge(left, right) ⇒ Object
Perform a deep merge of hashes, returning the result as a new hash.
-
.deep_merge!(left, right) ⇒ Object
Perform a deep merge of the right hash into the left hash.
-
.time(time) ⇒ Object
Try to parse any string into a Time object.
Class Method Details
.array(object) ⇒ Object
Return a array no matter what.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/supplejack/util.rb', line 16 def array(object) case object when Array object when NilClass [] else [object] end end |
.deep_merge(left, right) ⇒ Object
Perform a deep merge of hashes, returning the result as a new hash. See #deep_merge_into for rules used to merge the hashes
Parameters
- left<Hash>
-
Hash to merge
- right<Hash>
-
The other hash to merge
Returns
- Hash
-
New hash containing the given hashes deep-merged.
56 57 58 |
# File 'lib/supplejack/util.rb', line 56 def deep_merge(left, right) deep_merge_into({}, left, right) end |
.deep_merge!(left, right) ⇒ Object
Perform a deep merge of the right hash into the left hash
Parameters
- left
-
Hash to receive merge
- right
-
Hash to merge into left
Returns
- Hash
-
left
72 73 74 |
# File 'lib/supplejack/util.rb', line 72 def deep_merge!(left, right) deep_merge_into(left, left, right) end |
.time(time) ⇒ Object
Try to parse any string into a Time object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/supplejack/util.rb', line 30 def time(time) begin if time.is_a?(String) time = Time.parse(time) elsif time.is_a?(Time) || time.is_a?(DateTime) time = time end rescue time = nil end time end |