Sha256: 52258fb5474597bf6b306861fb219115bc2d7951fd4c687c1afaada7759f492c
Contents?: true
Size: 1.38 KB
Versions: 4
Compression:
Stored size: 1.38 KB
Contents
module VORuby module VOTables module VOTable # Miscellaneous classes that don't fit elsewhere. module Misc # An exception thrown when the incoming type does not match # the expected value. class TypeException < Exception # [_obj_:] # The object itself. # [_prototype_:] # The prototype of the expected class. def initialize(obj=nil, prototype=nil) super("Invalid type: #{obj.class} (#{obj}) != #{prototype}") end end # A class which checks to see whether the type of the incoming class # matches expectation. class TypeCheck attr_accessor :obj, :proto # [_obj_:] # The object in question. # [_proto_:] # The prototype of the expected class. 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 # Check to see whether the class is of the expected type. def check raise TypeException.new(@obj, @proto) if @obj and !@obj.is_a?(@proto) end def to_s "{object=#{@obj};prototype=#{@proto}}" end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
voruby-1.0.2 | lib/voruby/votables/misc.rb |
voruby-1.0.1 | lib/voruby/votables/misc.rb |
voruby-1.1 | lib/voruby/votables/misc.rb |
voruby-1.1.1 | lib/voruby/votables/misc.rb |