Module: FunRuby::Hash
Overview
Module containing methods for hashes
Class Method Summary collapse
-
.compact(keys = F._, hash = F._) ⇒ Object
Returns a new hash without all key-valued pairs.
-
.dig(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys.
-
.dig!(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys.
-
.fetch(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key.
-
.fetch_values(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns an array of values stored by given keys If any key is missed in the given hash KeyError is raised with the first missed key.
-
.fetch_with(key = F._, fallback = F._, hash = F._) ⇒ Object
Returns a value stored by a given key.
-
.get(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key.
-
.keys(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored keys.
-
.merge(first = F._, second = F._) ⇒ Hash
Merges two hashes.
-
.put(key = F._, value = F._, hash = F._) ⇒ Hash
Puts a value by a given key.
-
.reject(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash excluding pairs for which a given function returns true.
-
.select(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash containing only pairs for which a given function returns true.
-
.slice(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash.
-
.slice!(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash.
-
.transform_keys(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated keys calculated as a result returned from a given function.
-
.transform_values(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated values calculated as a result returned from a given function.
-
.values(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored values.
-
.values_at(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns an array of values stored by given keys If a key is missed the default value is returned.
Instance Method Summary collapse
-
#compact(keys = F._, hash = F._) ⇒ Object
Returns a new hash without all key-valued pairs.
-
#dig(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys.
-
#dig!(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys.
-
#fetch(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key.
-
#fetch_values(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns an array of values stored by given keys If any key is missed in the given hash KeyError is raised with the first missed key.
-
#fetch_with(key = F._, fallback = F._, hash = F._) ⇒ Object
Returns a value stored by a given key.
-
#get(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key.
-
#keys(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored keys.
-
#merge(first = F._, second = F._) ⇒ Hash
Merges two hashes.
-
#put(key = F._, value = F._, hash = F._) ⇒ Hash
Puts a value by a given key.
-
#reject(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash excluding pairs for which a given function returns true.
-
#select(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash containing only pairs for which a given function returns true.
-
#slice(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash.
-
#slice!(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash.
-
#transform_keys(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated keys calculated as a result returned from a given function.
-
#transform_values(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated values calculated as a result returned from a given function.
-
#values(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored values.
-
#values_at(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns an array of values stored by given keys If a key is missed the default value is returned.
Class Method Details
.compact(keys = F._, hash = F._) ⇒ Object
Returns a new hash without all key-valued pairs
407 408 409 |
# File 'lib/fun_ruby/hash.rb', line 407 def compact(keys = F._, hash = F._) curry_implementation(:compact, keys, hash) end |
.dig(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys. If a value of any level key of the chain is not found nil is returned.
373 374 375 |
# File 'lib/fun_ruby/hash.rb', line 373 def dig(keys = F._, hash = F._) curry_implementation(:dig, keys, hash) end |
.dig!(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys. If a value of any level key of the chain is not found KeyError is raised
394 395 396 |
# File 'lib/fun_ruby/hash.rb', line 394 def dig!(keys = F._, hash = F._) curry_implementation(:dig!, keys, hash) end |
.fetch(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key. If there is no given key it raises error
77 78 79 |
# File 'lib/fun_ruby/hash.rb', line 77 def fetch(key = F._, hash = F._) curry_implementation(:fetch, key, hash) end |
.fetch_values(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns an array of values stored by given keys If any key is missed in the given hash KeyError is raised with the first missed key
265 266 267 |
# File 'lib/fun_ruby/hash.rb', line 265 def fetch_values(keys = F._, hash = F._) curry_implementation(:fetch_values, keys, hash) end |
.fetch_with(key = F._, fallback = F._, hash = F._) ⇒ Object
Returns a value stored by a given key. If there is no given key it calls a given fallback.
113 114 115 |
# File 'lib/fun_ruby/hash.rb', line 113 def fetch_with(key = F._, fallback = F._, hash = F._) curry_implementation(:fetch_with, key, fallback, hash) end |
.get(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key. If there is no given key it return a default value
43 44 45 |
# File 'lib/fun_ruby/hash.rb', line 43 def get(key = F._, hash = F._) curry_implementation(:get, key, hash) end |
.keys(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored keys
316 317 318 |
# File 'lib/fun_ruby/hash.rb', line 316 def keys(hash = F._) curry_implementation(:keys, hash) end |
.merge(first = F._, second = F._) ⇒ Hash
Merges two hashes. The key-value pairs from the second to the first. If the key is already taken the current value will be replaced.
193 194 195 |
# File 'lib/fun_ruby/hash.rb', line 193 def merge(first = F._, second = F._) curry_implementation(:merge, first, second) end |
.put(key = F._, value = F._, hash = F._) ⇒ Hash
Puts a value by a given key. If the key is already taken the current value will be replaced.
149 150 151 |
# File 'lib/fun_ruby/hash.rb', line 149 def put(key = F._, value = F._, hash = F._) curry_implementation(:put, key, value, hash) end |
.reject(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash excluding pairs for which a given function returns true
352 353 354 |
# File 'lib/fun_ruby/hash.rb', line 352 def reject(function = F._, hash = F._) curry_implementation(:reject, function, hash) end |
.select(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash containing only pairs for which a given function returns true
334 335 336 |
# File 'lib/fun_ruby/hash.rb', line 334 def select(function = F._, hash = F._) curry_implementation(:select, function, hash) end |
.slice(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash. If keys are missed in the given hash the corresponded key will be absent in the result hash.
227 228 229 |
# File 'lib/fun_ruby/hash.rb', line 227 def slice(keys = F._, hash = F._) curry_implementation(:slice, keys, hash) end |
.slice!(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash. If keys are missed in the given hash KeyError is raised
246 247 248 |
# File 'lib/fun_ruby/hash.rb', line 246 def slice!(keys = F._, hash = F._) curry_implementation(:slice!, keys, hash) end |
.transform_keys(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated keys calculated as a result returned from a given function
422 423 424 |
# File 'lib/fun_ruby/hash.rb', line 422 def transform_keys(function = F._, hash = F._) curry_implementation(:transform_keys, function, hash) end |
.transform_values(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated values calculated as a result returned from a given function
437 438 439 |
# File 'lib/fun_ruby/hash.rb', line 437 def transform_values(function = F._, hash = F._) curry_implementation(:transform_values, function, hash) end |
.values(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored values
300 301 302 |
# File 'lib/fun_ruby/hash.rb', line 300 def values(hash = F._) curry_implementation(:values, hash) end |
Instance Method Details
#compact(keys = F._, hash = F._) ⇒ Object
Returns a new hash without all key-valued pairs
407 408 409 |
# File 'lib/fun_ruby/hash.rb', line 407 def compact(keys = F._, hash = F._) curry_implementation(:compact, keys, hash) end |
#dig(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys. If a value of any level key of the chain is not found nil is returned.
373 374 375 |
# File 'lib/fun_ruby/hash.rb', line 373 def dig(keys = F._, hash = F._) curry_implementation(:dig, keys, hash) end |
#dig!(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns a value stored by a given chain of keys. If a value of any level key of the chain is not found KeyError is raised
394 395 396 |
# File 'lib/fun_ruby/hash.rb', line 394 def dig!(keys = F._, hash = F._) curry_implementation(:dig!, keys, hash) end |
#fetch(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key. If there is no given key it raises error
77 78 79 |
# File 'lib/fun_ruby/hash.rb', line 77 def fetch(key = F._, hash = F._) curry_implementation(:fetch, key, hash) end |
#fetch_values(keys = F._, hash = F._) ⇒ ::Array[Object]
Returns an array of values stored by given keys If any key is missed in the given hash KeyError is raised with the first missed key
265 266 267 |
# File 'lib/fun_ruby/hash.rb', line 265 def fetch_values(keys = F._, hash = F._) curry_implementation(:fetch_values, keys, hash) end |
#fetch_with(key = F._, fallback = F._, hash = F._) ⇒ Object
Returns a value stored by a given key. If there is no given key it calls a given fallback.
113 114 115 |
# File 'lib/fun_ruby/hash.rb', line 113 def fetch_with(key = F._, fallback = F._, hash = F._) curry_implementation(:fetch_with, key, fallback, hash) end |
#get(key = F._, hash = F._) ⇒ Object
Returns a value stored by a given key. If there is no given key it return a default value
43 44 45 |
# File 'lib/fun_ruby/hash.rb', line 43 def get(key = F._, hash = F._) curry_implementation(:get, key, hash) end |
#keys(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored keys
316 317 318 |
# File 'lib/fun_ruby/hash.rb', line 316 def keys(hash = F._) curry_implementation(:keys, hash) end |
#merge(first = F._, second = F._) ⇒ Hash
Merges two hashes. The key-value pairs from the second to the first. If the key is already taken the current value will be replaced.
193 194 195 |
# File 'lib/fun_ruby/hash.rb', line 193 def merge(first = F._, second = F._) curry_implementation(:merge, first, second) end |
#put(key = F._, value = F._, hash = F._) ⇒ Hash
Puts a value by a given key. If the key is already taken the current value will be replaced.
149 150 151 |
# File 'lib/fun_ruby/hash.rb', line 149 def put(key = F._, value = F._, hash = F._) curry_implementation(:put, key, value, hash) end |
#reject(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash excluding pairs for which a given function returns true
352 353 354 |
# File 'lib/fun_ruby/hash.rb', line 352 def reject(function = F._, hash = F._) curry_implementation(:reject, function, hash) end |
#select(function = F._, hash = F._) ⇒ ::Array[Object]
Returns a new hash containing only pairs for which a given function returns true
334 335 336 |
# File 'lib/fun_ruby/hash.rb', line 334 def select(function = F._, hash = F._) curry_implementation(:select, function, hash) end |
#slice(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash. If keys are missed in the given hash the corresponded key will be absent in the result hash.
227 228 229 |
# File 'lib/fun_ruby/hash.rb', line 227 def slice(keys = F._, hash = F._) curry_implementation(:slice, keys, hash) end |
#slice!(keys = F._, hash = F._) ⇒ Hash
Builds a new hash with only given keys from a given hash. If keys are missed in the given hash KeyError is raised
246 247 248 |
# File 'lib/fun_ruby/hash.rb', line 246 def slice!(keys = F._, hash = F._) curry_implementation(:slice!, keys, hash) end |
#transform_keys(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated keys calculated as a result returned from a given function
422 423 424 |
# File 'lib/fun_ruby/hash.rb', line 422 def transform_keys(function = F._, hash = F._) curry_implementation(:transform_keys, function, hash) end |
#transform_values(function = F._, hash = F._) ⇒ Object
Returns a new hash with updated values calculated as a result returned from a given function
437 438 439 |
# File 'lib/fun_ruby/hash.rb', line 437 def transform_values(function = F._, hash = F._) curry_implementation(:transform_values, function, hash) end |
#values(hash = F._) ⇒ ::Array[Object]
Returns an array of all stored values
300 301 302 |
# File 'lib/fun_ruby/hash.rb', line 300 def values(hash = F._) curry_implementation(:values, hash) end |