Class: Quack::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/quack/type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Type

Returns a new instance of Type.



5
6
7
# File 'lib/quack/type.rb', line 5

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/quack/type.rb', line 3

def value
  @value
end

Class Method Details

.already_coerced?(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/quack/type.rb', line 14

def already_coerced?(value)
  built_in_types.include?(value.class)
end

.built_in_typesObject



10
11
12
# File 'lib/quack/type.rb', line 10

def built_in_types
  []
end

Instance Method Details

#already_coerced?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/quack/type.rb', line 19

def already_coerced?
  self.class.already_coerced?(value)
end

#to_coercedObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/quack/type.rb', line 23

def to_coerced
  raise NotImplementedError
end

#to_sObject



31
32
33
# File 'lib/quack/type.rb', line 31

def to_s
  to_coerced.to_s
end

#type_matches?(other) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/quack/type.rb', line 27

def type_matches?(other)
  self.class == other.class
end