Class: Camille::Types::BooleanLiteral
- Defined in:
- lib/camille/types/boolean_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) ⇒ BooleanLiteral
constructor
A new instance of BooleanLiteral.
- #literal ⇒ Object
Methods inherited from BasicType
&, #&, #[], [], directly_instantiable?, inherited, instance, #transform, #|, |
Constructor Details
#initialize(value) ⇒ BooleanLiteral
Returns a new instance of BooleanLiteral.
8 9 10 11 12 13 14 15 |
# File 'lib/camille/types/boolean_literal.rb', line 8 def initialize value if value == true || value == false @value = value @fingerprint = Digest::MD5.hexdigest "#{self.class.name}#{@value}" else raise ArgumentError.new("Expecting true or false, got #{value.inspect}") end end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/camille/types/boolean_literal.rb', line 6 def value @value end |
Instance Method Details
#check(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/camille/types/boolean_literal.rb', line 17 def check value if value == @value Camille::Checked.new(fingerprint, value) else Camille::TypeError.new("Expected boolean literal #{@value.inspect}, got #{value.inspect}.") end end |
#literal ⇒ Object
25 26 27 |
# File 'lib/camille/types/boolean_literal.rb', line 25 def literal @value.to_s end |