Class: Camille::Types::BooleanLiteral

Inherits:
BasicType
  • Object
show all
Defined in:
lib/camille/types/boolean_literal.rb

Defined Under Namespace

Classes: ArgumentError

Instance Attribute Summary collapse

Attributes inherited from BasicType

#fingerprint

Instance Method Summary collapse

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

#valueObject (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

#literalObject



25
26
27
# File 'lib/camille/types/boolean_literal.rb', line 25

def literal
  @value.to_s
end