class Rstruct::Registry
Constants
- DEFAULT_REGISTRY
Attributes
inherits[R]
name[R]
Public Class Methods
new(name, *inherits)
click to toggle source
# File lib/rstruct/registry.rb, line 13 def initialize(name, *inherits) @name = name.to_sym @registry = Hash.new() @inherits = [] if @name != :default @inherits << DEFAULT_REGISTRY end @inherits.concat(inherits).uniq! end
Public Instance Methods
get(typ)
click to toggle source
# File lib/rstruct/registry.rb, line 32 def get(typ) if t=@registry[typ] return t else @inherits.each do |inc| if t=inc.get(typ) return t end end return nil end end
Also aliased as: []
register(typ, *names)
click to toggle source
# File lib/rstruct/registry.rb, line 58 def register(typ, *names) names.each do |n| set(n.to_sym,typ) end end
set(n,typ)
click to toggle source
# File lib/rstruct/registry.rb, line 47 def set(n,typ) if n.nil? raise(TypeConflictError, "can't register nil type") elsif v=get(n) raise(TypeConflictError, "type already registered: #{n} => #{v.inspect}" ) end @registry[n]=typ end
Also aliased as: []=
typedef(p,t,opts={})
click to toggle source
# File lib/rstruct/registry.rb, line 24 def typedef(p,t,opts={}) if (pt = get(p)) set(t, pt) else raise(InvalidTypeError, "unknown type: #{p}") end end