Class: Hash
- 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
Class Method Summary collapse
-
.zip(keys, values, default = nil, &block) ⇒ Object
Create a hash from an array of keys and corresponding values.
Instance Method Summary collapse
-
#extractable_options? ⇒ Boolean
By default, only instances of Hash itself are extractable.
-
#to_mash ⇒ Mash
Convert to Mash.
Methods included from Gorillib::Hashlike::Serialization
Methods included from Gorillib::Hashlike::ReverseMerge
#reverse_merge, #reverse_merge!
Methods included from Gorillib::Hashlike::DeepCompact
Methods included from Gorillib::Hashlike::DeepMerge
Methods included from Gorillib::Hashlike::DeepDup
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.
7 8 9 |
# File 'lib/gorillib/array/extract_options.rb', line 7 def instance_of?(Hash) end |
#to_mash ⇒ Mash
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'].
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 |