Class: Hash

Inherits:
Object show all
Includes:
Gorillib::Hashlike::Compact, Gorillib::Hashlike::DeepCompact, Gorillib::Hashlike::DeepDup, Gorillib::Hashlike::DeepMerge, Gorillib::Hashlike::Keys, Gorillib::Hashlike::ReverseMerge, Gorillib::Hashlike::Serialization, Gorillib::Hashlike::Slice
Defined in:
lib/gorillib/hash/zip.rb,
lib/gorillib/hash/keys.rb,
lib/gorillib/hash/mash.rb,
lib/gorillib/hash/slice.rb,
lib/gorillib/hash/compact.rb,
lib/gorillib/hash/deep_dup.rb,
lib/gorillib/hash/deep_merge.rb,
lib/gorillib/hash/deep_compact.rb,
lib/gorillib/hash/reverse_merge.rb,
lib/gorillib/array/extract_options.rb,
lib/gorillib/serialization/to_wire.rb

Direct Known Subclasses

Mash

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gorillib::Hashlike::Serialization

#to_wire

Methods included from Gorillib::Hashlike::ReverseMerge

#reverse_merge, #reverse_merge!

Methods included from Gorillib::Hashlike::DeepCompact

#deep_compact!

Methods included from Gorillib::Hashlike::DeepMerge

#deep_merge, #deep_merge!

Methods included from Gorillib::Hashlike::DeepDup

#deep_dup

Methods included from Gorillib::Hashlike::Compact

#compact, #compact!, #compact_blank, #compact_blank!

Methods included from Gorillib::Hashlike::Slice

#except, #except!, #extract!, #only, #only!, #slice, #slice!

Methods included from Gorillib::Hashlike::Keys

#assert_valid_keys, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!

Class Method Details

.zip(keys, values, default = nil, &block) ⇒ Object

Create a hash from an array of keys and corresponding values.



5
6
7
8
9
# File 'lib/gorillib/hash/zip.rb', line 5

def self.zip(keys, values, default=nil, &block)
  hash = block_given? ? Hash.new(&block) : Hash.new(default)
  keys.zip(values){|key,val| hash[key]=val }
  hash
end

Instance Method Details

#extractable_options?Boolean

By default, only instances of Hash itself are extractable. Subclasses of Hash may implement this method and return true to declare themselves as extractable. If a Hash is extractable, Array#extract_options! pops it from the Array when it is the last element of the Array.

Returns:

  • (Boolean)


7
8
9
# File 'lib/gorillib/array/extract_options.rb', line 7

def extractable_options?
  instance_of?(Hash)
end

#to_mashMash

Convert to Mash. This class has semantics of ActiveSupport's HashWithIndifferentAccess and we only have it so that people can write params[:key] instead of params['key'].

Returns:

  • (Mash)

    This hash as a Mash for string or symbol key access.



8
9
10
11
12
# File 'lib/gorillib/hash/mash.rb', line 8

def to_mash
  hsh = Mash.new(self)
  hsh.default = default
  hsh
end