Class: Kumi::Core::Analyzer::AnalysisState
- Inherits:
-
Object
- Object
- Kumi::Core::Analyzer::AnalysisState
- Defined in:
- lib/kumi/core/analyzer/analysis_state.rb
Overview
Simple immutable state wrapper to prevent accidental mutations between passes
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a value (same as hash access).
-
#initialize(data = {}) ⇒ AnalysisState
constructor
A new instance of AnalysisState.
-
#key?(key) ⇒ Boolean
(also: #has_key?)
Check if key exists (same as hash).
-
#keys ⇒ Object
Get all keys (same as hash).
-
#to_h ⇒ Object
Convert back to hash for final result.
-
#with(key, value) ⇒ Object
Create new state with additional data (simple and clean).
Constructor Details
#initialize(data = {}) ⇒ AnalysisState
Returns a new instance of AnalysisState.
8 9 10 |
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 8 def initialize(data = {}) @data = data.dup.freeze end |
Instance Method Details
#[](key) ⇒ Object
Get a value (same as hash access)
13 14 15 |
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 13 def [](key) @data[key] end |
#key?(key) ⇒ Boolean Also known as: has_key?
Check if key exists (same as hash)
18 19 20 |
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 18 def key?(key) @data.key?(key) end |
#keys ⇒ Object
Get all keys (same as hash)
25 26 27 |
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 25 def keys @data.keys end |
#to_h ⇒ Object
Convert back to hash for final result
35 36 37 |
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 35 def to_h @data.dup end |
#with(key, value) ⇒ Object
Create new state with additional data (simple and clean)
30 31 32 |
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 30 def with(key, value) AnalysisState.new(@data.merge(key => value)) end |