Module: Sparsify
- Extended by:
- GuardMethods, UtilityMethods
- Defined in:
- lib/sparsify.rb,
lib/sparsify/version.rb,
lib/sparsify/guard_methods.rb,
lib/sparsify/utility_methods.rb
Overview
Provides sparse-key access to a Hash.
‘foo’=>{‘bar’=>‘bingo’}.sparse #=> ‘foo‘foo.bar’=>‘bingo’ ‘foo‘foo.bar’=>‘bingo’.unsparse => ‘foo’=>{‘bar’=>‘bingo’}
Defined Under Namespace
Modules: GuardMethods, UtilityMethods
Constant Summary collapse
- DEFAULT_SEPARATOR =
The default separator, used if not specified in command’s options hash.
'.'.freeze
- VERSION =
'1.0.1'
Instance Method Summary collapse
-
#sparse(options = {}) ⇒ Hash<String,Object>
Returns a sparse version of self using the options provided.
-
#sparse!(options = {}) ⇒ Hash<String,Object>
Replaces self with sparse version of itself.
-
#sparse_each(options = {}, &block) ⇒ Object
Used internally by both Sparsify::Utility#sparse and Sparsify::Utility#unsparse.
-
#sparse_get(sparse_key, options = {}) ⇒ Object
Follows semantics of Hash#[] without support for Hash#default_proc.
-
#unsparse(options = {}) ⇒ Hash<String,Object>
Returns a deeply-nested hash version of self.
-
#unsparse!(options = {}) ⇒ Hash<String,Object>
Replaces self with deeply-nested version of self.
Methods included from GuardMethods
Methods included from UtilityMethods
Instance Method Details
#sparse(options = {}) ⇒ Hash<String,Object>
Returns a sparse version of self using the options provided.
27 28 29 |
# File 'lib/sparsify.rb', line 27 def sparse( = {}) Sparsify.sparse(self, ) end |
#sparse!(options = {}) ⇒ Hash<String,Object>
Replaces self with sparse version of itself.
35 36 37 |
# File 'lib/sparsify.rb', line 35 def sparse!( = {}) self.replace(sparse, ) end |
#sparse_eachrm(options = {}) {|| ... } ⇒ void #sparse_each(options = {}) ⇒ Enumerator<(sparse_key,value)>
Used internally by both Sparsify::Utility#sparse and Sparsify::Utility#unsparse
50 51 52 |
# File 'lib/sparsify.rb', line 50 def sparse_each( = {}, &block) Sparsify.sparse_each(self, , &block) end |
#sparse_get(sparse_key, options = {}) ⇒ Object
Follows semantics of Hash#[] without support for Hash#default_proc
68 69 70 |
# File 'lib/sparsify.rb', line 68 def sparse_fetch(*args, &block) Sparsify.sparse_fetch(self, *args, &block) end |
#unsparse(options = {}) ⇒ Hash<String,Object>
Returns a deeply-nested hash version of self.
85 86 87 |
# File 'lib/sparsify.rb', line 85 def unsparse( = {}) Sparsify.unsparse(self, ) end |
#unsparse!(options = {}) ⇒ Hash<String,Object>
Replaces self with deeply-nested version of self.
93 94 95 |
# File 'lib/sparsify.rb', line 93 def unsparse!( = {}) self.replace(unsparse, ) end |