Class: StrongJSON::Type::Literal
- Inherits:
-
Object
- Object
- StrongJSON::Type::Literal
- Defined in:
- lib/strong_json/type.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #coerce(value, path: ErrorPath.root(self)) ⇒ Object
-
#initialize(value) ⇒ Literal
constructor
A new instance of Literal.
- #to_s ⇒ Object
Methods included from WithAlias
Methods included from Match
Constructor Details
#initialize(value) ⇒ Literal
Returns a new instance of Literal.
131 132 133 |
# File 'lib/strong_json/type.rb', line 131 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
129 130 131 |
# File 'lib/strong_json/type.rb', line 129 def value @value end |
Instance Method Details
#==(other) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/strong_json/type.rb', line 144 def ==(other) if other.is_a?(Literal) # @type var other: Literal<any> other.value == value end end |
#coerce(value, path: ErrorPath.root(self)) ⇒ Object
139 140 141 142 |
# File 'lib/strong_json/type.rb', line 139 def coerce(value, path: ErrorPath.root(self)) raise TypeError.new(path: path, value: value) unless (_ = self.value) == value value end |
#to_s ⇒ Object
135 136 137 |
# File 'lib/strong_json/type.rb', line 135 def to_s self.alias&.to_s || (_ = @value).inspect end |