Sha256: 3c6cbc8119c0f145cf9175c21e2c9eeab188564e5731827fc9f170caa680bd72
Contents?: true
Size: 846 Bytes
Versions: 2
Compression:
Stored size: 846 Bytes
Contents
class Hash def path_to_nested_key(key) self.each do |k,v| path = [k] if k == key return path elsif v.is_a? Hash nested_path = v.path_to_nested_key(key) nested_path ? (return path + nested_path) : nil end end return nil end def self.nest(path, value) hash_constructor = lambda { |h, k| h[k] = Hash.new(&hash_constructor) } nested_hash = Hash.new(&hash_constructor) last_key = path.last path.inject(nested_hash) { |h, k| (k == last_key) ? h[k] = value : h[k] } nested_hash end end class Class def simple_name self.to_s.split("::").last end end class Object def not_blank? !self.blank? end end class File def self.read_from_unknown(file) case file when String File.read(file) when IO file.read end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
quickbooks_api-0.1.1 | lib/quickbooks/support/monkey_patches.rb |
quickbooks_api-0.1.0 | lib/quickbooks/support/monkey_patches.rb |