Dict
Dict implements part of the Ruby's Hash API.
module methods:
value methods:
- <<
- any?
- all?
- clear
- clone
- delete
- delete_if
- each
- empty?
- fetch
- keep_if
- key
- keys
- key?
- include?
- member?
- size
- merge
- merge!
- replace
- reject
- reject!
- select
- select!
- shift
- to_l
- value?
- values
- values@
:
Create and return a new Dict
value.
(Dict :) -> dict
<<
Store a new pair of key
-value
into dict. If value
is not
provided, nil
is default value.
(Dict << key(string) [value(any)]) -> string
any?
Passes each dict key
-value
pair into f
as first and second
parameter to evaluate a value which will be converted to true/false.
Any of true
result of f
will stop loop call and return true
,
otherwise return false
.
(Dict any? [f(lambda)]) -> bool
all?
Passes each dict key
-value
pair into f
as first and second
parameter to evaluate a value which will be converted to true/false.
Return true
if all results are true
, or false
.
(Dict all? [f(lambda)]) -> bool
clear
Remove all key
-value
pairs from Dict
, and return itself.
(Dict clear) -> self
clone
Return a new copy of Dict
.
(Dict clone) -> dict
delete
Delete key
from Dict
, and return value
if key
is existing key or nil
.
(Dict delete key(string)) -> any
delete_if
Passes every key
and value
pair to f
to evaluate. It will delete key
from Dict
if result is true
.
(Dict delete_if f(lambda)) -> self
each
Passes each key
and value
pair to f
to evaluate. returns Dict
itself.
(Dict each f(lambda)) -> self
empty?
Test if the Dict
has no key.
(Dict empty?) -> bool
fetch
Looks up key
in Dict
. If the key
exists, the value
is returned.
Otherwise, it returns default
. There is a special case of default
.
If default
is a Lambda
, the value
will be passed to default
lambda
as a parameter, and then return the final result of lambda
.
(Dict fetch key(string) [default(any)]) -> any
keep_if
Passes every key
and value
pair to f
to evaluate. It will delete key
from Dict
if result is false
.
(Dict keep_if f(lambda)) -> self
key
If value
is stored value in Dict
then return the corresponding key
.
Otherwise, return nil
.
(Dict key value(any)) -> string
keys
Returns List of all keys.
(Dict keys) -> list
key?
Test if key
is a key in Dict
.
(Dict key? key(string)) -> bool
include?
It is an alias of key?
(Dict include? key(string)) -> bool
member?
It is an alias of key?
(Dict member? key(string)) -> bool
size
Return the number of key
-value
pairs.
(Dict size) -> int
merge
Returns a new Dict merged from Dict
and d
. If
a key
exists in both dict, the value
in the Dict
is retained.
If f
is provided, then value
will be passed to f
as a parameter,
and then the calculation result of f
will replace the value
.
(Dict merge d(dict) [f(lambda)]) -> dict
merge!
Combine d
into Dict
. If the key
does not exist in Dict
. it will
be merged directly. If the key already exists and f
is provided, then
the value
corresponding to the key
is as a parameter to calculate f
,
and the result is as the value
in the Dict
.
(Dict merge! d(dict) [f(lambda)]) -> self
replace
Replace all key
-value
pairs of Dict
with the pairs of d
.
(Dict replace d(dict)) -> dict
reject
Create a new dict with key
-value
pairs copied from Dict
which
passes to f
as first and second parameters, and is evaluated to false
.
(Dict reject f(lambda)) -> dict
reject!
Remove the key
-value
pairs from Dict
which passes to f
as first
and second parameters, and is evaluated to true
.
(Dict reject! f(lambda)) -> self
select
Create a new dict with key
-value
pairs copied from Dict
which
passes to f
as first and second parameters, and is evaluated to true
.
(Dict select f(lambda)) -> dict
select!
Remove the key
-value
pairs from Dict
which passes to f
as first
and second parameters, and is evaluated to false
.
(Dict select! f(lambda)) -> self
shift
Pop up a key
-value
pair as 2-element list, where first is key
and
second is value
.
(Dict shift) -> [string, any]
to_l
Returns a list of 2-element list of key
-value
pair.
(Dict to_l) -> list
value?
Test if value
is stored in Dict
.
(Dict value? value(any)) -> bool
values
Returns a list of all value
stored in Dict
.
(Dict values) -> list
values@
Return a list containing the value
corresponding to all key
.
If key
does not exist, value
will be nil
.
(Dict values@ key(string)...) -> list