Sha256: 6d33924835d2ddf19e6df78226d292f90fe7ca673e153f38e5dc1288cb3f6b5e

Contents?: true

Size: 838 Bytes

Versions: 6

Compression:

Stored size: 838 Bytes

Contents

class Hash

  def path_to_nested_key(key)
    each do |k,v|
      path = [k]
      if k == key
        return path
      elsif v.is_a? Hash
        nested_path = v.path_to_nested_key(key)
        return (path + nested_path) if nested_path
      end
    end
    return nil
  end

  def self.nest(path, value)
    hash_constructor = Proc.new { |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

6 entries across 6 versions & 1 rubygems

Version Path
quickbooks_api-0.1.7 lib/quickbooks/support/monkey_patches.rb
quickbooks_api-0.1.6 lib/quickbooks/support/monkey_patches.rb
quickbooks_api-0.1.5 lib/quickbooks/support/monkey_patches.rb
quickbooks_api-0.1.4 lib/quickbooks/support/monkey_patches.rb
quickbooks_api-0.1.3 lib/quickbooks/support/monkey_patches.rb
quickbooks_api-0.1.2 lib/quickbooks/support/monkey_patches.rb