Class: Gloo::Verbs::Eval

Inherits:
Core::Verb show all
Defined in:
lib/gloo/verbs/eval.rb

Constant Summary collapse

KEYWORD =
'eval'.freeze
KEYWORD_SHORT =
'noop'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Verb

#params, #tokens

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Verb

#display_value, help, inherited, #initialize, #type_display

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Verb

Class Method Details

.doc_dataObject

Get the verb's documentation data.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gloo/verbs/eval.rb', line 48

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'Evaluate an expression and put the result ' \
      'into it, without any other action. Unlike put it does ' \
      'not store the result in a named object, and unlike show ' \
      'it does not print it. Primarily used in tests: assert ' \
      'and refute check the value of it, so eval is the bridge ' \
      'for expressions and comparisons that do not already ' \
      'leave a boolean there.',
    :syntax => [ 'eval {expression}' ],
    :parameters => [
      '{expression} — The expression that will be evaluated. The expression is optional. If not provided, eval will result in true.'
    ],
    :result => 'The result of the expression evaluation is put ' \
      'into it. No other action is performed.',
    :examples => <<~EXAMPLES.strip,
    :notes => <<~NOTES.strip
      eval was added for the gloo-test framework. assert and refute
      only look at it; the common pattern is to run a verb or
      message, then 'eval it = {expected}' to compare the result to
      an expected value, then assert or refute. Bare eval (or its
      shortcut noop) sets it to true, which pairs with assert for
      'this state should hold' checks.
    NOTES
  }
end

.keywordObject

Get the Verb's keyword.



17
18
19
# File 'lib/gloo/verbs/eval.rb', line 17

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



24
25
26
# File 'lib/gloo/verbs/eval.rb', line 24

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#runObject

Run the verb.



31
32
33
34
35
36
37
38
39
# File 'lib/gloo/verbs/eval.rb', line 31

def run
  if @tokens.token_count > 1
    expr = Gloo::Expr::Expression.new( @engine, @tokens.params )
    result = expr.evaluate
    @engine.heap.it.set_to result
  else
    @engine.heap.it.set_to true
  end
end