Class: PortableExpressions::Scalar

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/portable_expressions/scalar.rb

Overview

A ‘Scalar` is the simplest object that can be evaluated. It holds a single `value`. When used in an `Expression`, this `value` must respond to the symbol (i.e. support the method) defined by the `Expression#operator`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serializable

#to_json

Constructor Details

#initialize(value) ⇒ Scalar

Returns a new instance of Scalar.



11
12
13
# File 'lib/portable_expressions/scalar.rb', line 11

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/portable_expressions/scalar.rb', line 9

def value
  @value
end

Instance Method Details

#as_jsonObject



19
20
21
22
23
# File 'lib/portable_expressions/scalar.rb', line 19

def as_json
  super.merge(
    value: value
  )
end

#to_sObject



15
16
17
# File 'lib/portable_expressions/scalar.rb', line 15

def to_s
  value.to_s
end