class Myst::TypeCheck::Scope
- Myst::TypeCheck::Scope
- Hash(String, Myst::TypeCheck::Type)
- Reference
- Object
Defined in:
typecheck/scope.crConstructors
Instance Method Summary
-
#[](key)
Returns the value for the key given by key.
- #[]=(key, value, always_create = false)
-
#[]?(key)
Returns the value for the key given by key.
- #find_or_assign(key, new_value)
-
#merge!(other : Scope, *, unionize = true, nilify nil_type : Type | Nil = nil)
Merge the entries of the given Scope into this one.
- #parent : Scope | Nil
- #parent=(parent : Scope | Nil)
- #parent? : Scope | Nil | Nil
Constructor Detail
Instance Method Detail
Returns the value for the key given by key.
If not found, returns the default value given by Hash.new
, otherwise raises KeyError
.
h = {"foo" => "bar"}
h["foo"] # => "bar"
h = Hash(String, String).new("bar")
h["foo"] # => "bar"
h = Hash(String, String).new { "bar" }
h["foo"] # => "bar"
h = Hash(String, String).new
h["foo"] # raises KeyError
Returns the value for the key given by key.
If not found, returns nil
. This ignores the default value set by Hash.new
.
h = {"foo" => "bar"}
h["foo"]? # => "bar"
h["bar"]? # => nil
h = Hash(String, String).new("bar")
h["foo"]? # => nil
Merge the entries of the given Scope into this one. If unionize
is
set to true, duplicate entries will be replaced in this scope with the
union of both. If it is false, other
will take precedence.
If nilify
is set to true, and a given key is not present in both
scopes, then the resulting type will be unioned with Nil in the merge.
nilify_left
is similar to nilify
, but only unions with Nil if the
key does not exist in the left hand side.