Sha256: 5dbddd8715e13b7871f30e4108a33dbae4473c429d4a24c9b7a26e73a314a0d7
Contents?: true
Size: 754 Bytes
Versions: 3
Compression:
Stored size: 754 Bytes
Contents
module Reality module Util module_function def oneify(val) return val unless val.is_a?(Array) val.size <= 1 ? val.first : val end def dig(what, *keys) return what if keys.empty? k = keys.shift if k == :* what.map { |el| dig(el, *keys) } else what.respond_to?(:[]) or fail ArgumentError, "Can't dig(#{keys}) in #{what.class}" res = what[k] or return nil dig(res, *keys) end end DEFAULT_REQUIRE_EXPLANATION = 'Please install `%s` in order to use this functionality.'.freeze def require_optional(gem, explanation = nil) require gem rescue LoadError raise LoadError, explanation || DEFAULT_REQUIRE_EXPLANATION % gem end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
reality-0.1.0.alpha3 | lib/reality/util.rb |
reality-0.1.0.alpha2 | lib/reality/util.rb |
reality-0.1.0.alpha | lib/reality/util.rb |