Class: Code::Object::Context
- Inherits:
-
Dictionary
- Object
- Code::Object
- Dictionary
- Code::Object::Context
- Defined in:
- lib/code/object/context.rb
Constant Summary
Constants inherited from Code::Object
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Attributes included from Concerns::Shared
Instance Method Summary collapse
- #code_lookup!(identifier) ⇒ Object
-
#initialize(*args, **_kargs, &_block) ⇒ Context
constructor
A new instance of Context.
- #merge(other) ⇒ Object
- #parent? ⇒ Boolean
Methods inherited from Dictionary
#<=>, #call, #code_any?, #code_clear, #code_compact, #code_compact!, #code_deep_duplicate, #code_delete, #code_delete_if, #code_delete_unless, #code_dig, #code_each, #code_empty?, #code_except, #code_fetch, #code_fetch_values, #code_flatten, #code_get, #code_has_key?, #code_has_value?, #code_invert, #code_keep_if, #code_keep_unless, #code_key, #code_keys, #code_merge, #code_merge!, #code_select, #code_select!, #code_set, #code_size, #code_to_context, #code_to_query, #code_transform_values, #code_values
Methods inherited from Code::Object
code_new, #code_new, maybe, #name, repeat, |
Methods included from Concerns::Shared
#<=>, #==, #as_json, #call, #code_and, #code_as_json, #code_compare, #code_deep_duplicate, #code_different, #code_duplicate, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_falsy?, #code_fetch, code_fetch, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_inclusive_range, #code_inspect, #code_less, #code_less_or_equal, #code_methods, #code_name, #code_nothing?, #code_or, #code_self, #code_set, code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ Context
Returns a new instance of Context.
8 9 10 11 |
# File 'lib/code/object/context.rb', line 8 def initialize(*args, **_kargs, &_block) super(args.first) @parent = args.second if args.second.is_a?(Dictionary) end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/code/object/context.rb', line 6 def parent @parent end |
Instance Method Details
#code_lookup!(identifier) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/code/object/context.rb', line 13 def code_lookup!(identifier) code_identifier = identifier.to_code if code_has_key?(code_identifier).truthy? self elsif parent? parent.code_lookup!(code_identifier) else raise Error, "#{code_identifier} is not defined" end end |
#merge(other) ⇒ Object
25 26 27 |
# File 'lib/code/object/context.rb', line 25 def merge(other) Context.new(raw.merge(other.raw), parent || other.parent) end |