Class: RDL::Type::ComputedType

Inherits:
Type show all
Defined in:
lib/rdl/types/computed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#canonical, leq, #nil_type?, #optional?, #to_contract, #vararg?

Constructor Details

#initialize(code) ⇒ ComputedType

Returns a new instance of ComputedType.



7
8
9
10
# File 'lib/rdl/types/computed.rb', line 7

def initialize(code)
  @code = code
  super()
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/rdl/types/computed.rb', line 5

def code
  @code
end

Instance Method Details

#<=(other) ⇒ Object



36
37
38
# File 'lib/rdl/types/computed.rb', line 36

def <=(other)
  ## TODO
end

#==(other) ⇒ Object Also known as: eql?



40
41
42
# File 'lib/rdl/types/computed.rb', line 40

def ==(other)
  ## TODO
end

#compute(bind) ⇒ Object

Raises:

  • (RuntimeError)


12
13
14
15
16
# File 'lib/rdl/types/computed.rb', line 12

def compute(bind)
  res = bind.eval(@code)
  raise RuntimeError, "Expected ComputedType to evaluate to type, instead got #{res}." unless res.is_a?(Type)
  res
end

#instantiate(inst) ⇒ Object

TODO

Figure out how to fill in the below methods.

I believe a ComputedType will always be evaluated to another RDL type before any of these methods would be called. Need to think about this though.



27
28
29
30
# File 'lib/rdl/types/computed.rb', line 27

def instantiate(inst)
  @inst = inst
  self
end

#to_sObject



18
19
20
# File 'lib/rdl/types/computed.rb', line 18

def to_s
  "``#{@code}``"
end

#widenObject



32
33
34
# File 'lib/rdl/types/computed.rb', line 32

def widen
  self
end