Class: YardExampleTest::Example::Evaluator
- Inherits:
-
Object
- Object
- YardExampleTest::Example::Evaluator
- Defined in:
- lib/yard_example_test/example/evaluator.rb
Overview
Manages binding creation and code evaluation for example expressions
Each Evaluator is constructed with a fallback binding (whose +self+ is the +Minitest::Spec+ instance, providing access to any methods included on YardExampleTest::Example such as +RSpec::Matchers+) and a snapshot of instance variables from the spec instance (set by +before+ hooks). These are used to build per-scope evaluation contexts that mirror the documented class's namespace.
Instance Method Summary collapse
-
#evaluate(code, bind) ⇒ Object
private
Evaluates a Ruby code string in the given scope.
-
#evaluate_with_assertion(code, bind) ⇒ Object, StandardError
private
Evaluates a Ruby code string, capturing any +StandardError+ as a value.
-
#initialize(fallback_binding:, instance_variables:) ⇒ Evaluator
constructor
private
Creates a new evaluator.
Constructor Details
#initialize(fallback_binding:, instance_variables:) ⇒ Evaluator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new evaluator
31 32 33 34 |
# File 'lib/yard_example_test/example/evaluator.rb', line 31 def initialize(fallback_binding:, instance_variables:) @fallback_binding = fallback_binding @instance_variables = instance_variables end |
Instance Method Details
#evaluate(code, bind) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates a Ruby code string in the given scope
51 52 53 |
# File 'lib/yard_example_test/example/evaluator.rb', line 51 def evaluate(code, bind) context(bind).eval(code) end |
#evaluate_with_assertion(code, bind) ⇒ Object, StandardError
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates a Ruby code string, capturing any +StandardError+ as a value
If evaluation raises a +StandardError+, the error itself is returned instead of propagating. This allows callers to compare raised errors against expected error values.
71 72 73 74 75 |
# File 'lib/yard_example_test/example/evaluator.rb', line 71 def evaluate_with_assertion(code, bind) evaluate(code, bind) rescue StandardError => e e end |