Class: Fictium::ParameterEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/fictium/evaluators/parameter_evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParameterEvaluator

Returns a new instance of ParameterEvaluator.



5
6
7
# File 'lib/fictium/evaluators/parameter_evaluator.rb', line 5

def initialize
  @params = ActiveSupport::HashWithIndifferentAccess.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_, **kwargs) ⇒ Object

rubocop:disable Style/MethodMissingSuper



18
19
20
# File 'lib/fictium/evaluators/parameter_evaluator.rb', line 18

def method_missing(name, *_, **kwargs) # rubocop:disable Style/MethodMissingSuper
  self[name] = validate_keys(**kwargs) if respond_to_missing?(name)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/fictium/evaluators/parameter_evaluator.rb', line 3

def params
  @params
end

Instance Method Details

#[](name) ⇒ Object



22
23
24
# File 'lib/fictium/evaluators/parameter_evaluator.rb', line 22

def [](name)
  @params[name]
end

#[]=(name, value) ⇒ Object



26
27
28
# File 'lib/fictium/evaluators/parameter_evaluator.rb', line 26

def []=(name, value)
  @params[name] = value
end

#evaluate_params(&block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/fictium/evaluators/parameter_evaluator.rb', line 9

def evaluate_params(&block)
  if block.arity == 1
    block.call(self)
  else
    instance_eval(&block)
  end
  @params
end