Class: VORuby::VOTables::VOTable::Misc::TypeCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/voruby/votables/misc.rb

Overview

A class which checks to see whether the type of the incoming class matches expectation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil, proto = nil) ⇒ TypeCheck

obj:

The object in question.

proto:

The prototype of the expected class.



30
31
32
33
34
35
36
# File 'lib/voruby/votables/misc.rb', line 30

def initialize(obj=nil, proto=nil)
#raise "TypeCheck must have an object" if obj == nil
#raise "TypeCheck must have a prototype" if proto == nil
	
@obj = obj
@proto = proto
end

Instance Attribute Details

#objObject

Returns the value of attribute obj.



24
25
26
# File 'lib/voruby/votables/misc.rb', line 24

def obj
  @obj
end

#protoObject

Returns the value of attribute proto.



24
25
26
# File 'lib/voruby/votables/misc.rb', line 24

def proto
  @proto
end

Instance Method Details

#checkObject

Check to see whether the class is of the expected type.

Raises:



39
40
41
# File 'lib/voruby/votables/misc.rb', line 39

def check
raise TypeException.new(@obj, @proto) if @obj and !@obj.is_a?(@proto)
end

#to_sObject



43
44
45
# File 'lib/voruby/votables/misc.rb', line 43

def to_s
"{object=#{@obj};prototype=#{@proto}}"
end