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.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/supplejack/util.rb', line 18 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.
58 59 60 |
# File 'lib/supplejack/util.rb', line 58 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
74 75 76 |
# File 'lib/supplejack/util.rb', line 74 def deep_merge!(left, right) deep_merge_into(left, left, right) end |
.time(time) ⇒ Object
Try to parse any string into a Time object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/supplejack/util.rb', line 32 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 |