Module: Gaskit::Helpers
- Defined in:
- lib/gaskit/helpers.rb
Class Method Summary collapse
-
.deep_compact(hash) ⇒ Hash
Applies deep compat on the provided hash.
-
.resolve_name(source) ⇒ String
Resolves the provide class’s name.
-
.time_execution { ... } ⇒ Array<Float, Object>
Measures the time taken for execution.
Class Method Details
.deep_compact(hash) ⇒ Hash
Applies deep compat on the provided hash.
22 23 24 25 26 27 |
# File 'lib/gaskit/helpers.rb', line 22 def deep_compact(hash) hash.each_with_object({}) do |(k, v), result| compacted = v.is_a?(Hash) ? deep_compact(v) : v result[k.to_sym] = compacted unless compacted.nil? end end |
.resolve_name(source) ⇒ String
Resolves the provide class’s name.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gaskit/helpers.rb', line 33 def resolve_name(source) case source when String, Symbol source.to_s when Class source.name else source.class.name end end |
.time_execution { ... } ⇒ Array<Float, Object>
Measures the time taken for execution.
10 11 12 13 14 15 16 |
# File 'lib/gaskit/helpers.rb', line 10 def time_execution start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = yield duration = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) [format("%.6f", duration), result] end |