Class: Camille::Types::StringLiteral
- Defined in:
- lib/camille/types/string_literal.rb
Defined Under Namespace
Classes: ArgumentError
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from BasicType
Instance Method Summary collapse
- #check(value) ⇒ Object
-
#initialize(value) ⇒ StringLiteral
constructor
A new instance of StringLiteral.
- #literal ⇒ Object
Methods inherited from BasicType
&, #&, #[], [], directly_instantiable?, inherited, instance, #transform, #|, |
Constructor Details
#initialize(value) ⇒ StringLiteral
Returns a new instance of StringLiteral.
8 9 10 11 12 13 14 15 |
# File 'lib/camille/types/string_literal.rb', line 8 def initialize value if value.is_a?(::String) @value = value @fingerprint = Digest::MD5.hexdigest "#{self.class.name}#{@value}" else raise ArgumentError.new("Expecting a string, got #{value.inspect}") end end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/camille/types/string_literal.rb', line 6 def value @value end |
Instance Method Details
#check(value) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/camille/types/string_literal.rb', line 17 def check value transformed = value.is_a?(Symbol) ? value.to_s : value if transformed == @value Camille::Checked.new(fingerprint, value) else Camille::TypeError.new("Expected string literal #{@value.inspect}, got #{value.inspect}.") end end |
#literal ⇒ Object
26 27 28 |
# File 'lib/camille/types/string_literal.rb', line 26 def literal @value.inspect end |