OpenCascade
OpenCascade is subclass of OpenObject, but differs in a few significant ways.
Mainly, and why it’s labeled a "cascade", every internal Hash is trandformed into an OpenCascade dynamically upon access. This makes it easy to create "cascading" references.
h = { :a => { :b => { :c => 1 } } } o = OpenCascade.new(h) o.a.b.c #=> 1
OpenCascade also has an inheritance feature which allows lookup to be passed on to a "parent" if a key is not found. Simple use the keyword option ++:inherit++ (or ++:parent++).
p = { :a => 1 } o = OpenCascade.new( {}, :inherit => p } o.a #=> 1
OpenCascade also supports acquisition which applies inheritance to every sub-access. Eg.
o = OpenCascade.new( { :a => 1, :q => {} }, :acquisition => true } o.q.a #=> 1
The two can, of course, be used together.
Methods
Public Class methods
[ show source ]
# File lib/facets/more/opencascade.rb, line 85 def initialize( init=nil, opt={} ) super( init ) @parent = opt[:inherit] || opt[:parent] @acquire = opt[:acquisition] ? true : false end
Public Instance methods
[ show source ]
# File lib/facets/more/opencascade.rb, line 121 def __parent__ ; @parent ; end
[ show source ]
# File lib/facets/more/opencascade.rb, line 122 def __parent__=(x) ; @parent = x ; end
[ show source ]
# File lib/facets/more/opencascade.rb, line 91 def method_missing( sym, *args ) type = sym.to_s[-1,1] name = sym.to_s.gsub(/[=!?]$/, '').to_sym if type == '=' @table[name] = args[0] elsif type == '!' and args.size > 0 @table[name] = args[0] self else if @table.key?(name) if Hash === @table[name] if @acquire self.__class__.new( @table[name], :inherit => self, :acquisition => true ) else self.__class__.new( @table[name] ) end else @table[name] end elsif @parent # error catch? @parent.__send__(name) else nil # Kernel.null # @table[name] = instance.class.new end end end