Class OpenCascade
In: lib/more/facets/opencascade.rb
Parent: OpenObject

OpenCascade

OpenCascade is subclass of OpenObject. It differs in a few significant ways.

The main reason this class is labeled "cascade", every internal Hash is transformed into an OpenCascade dynamically upon access. This makes it easy to create "cascading" references.

  h = { :x => { :y => { :z => 1 } } }
  c = OpenCascade[h]
  c.x.y.z  #=> 1

As soon as you access a node it automatically becomes an OpenCascade.

  c = OpenCascade.new   #=> #<OpenCascade:0x7fac3680ccf0 {}>
  c.r                   #=> #<OpenCascade:0x7fac368084c0 {}>
  c.a.b                 #=> #<OpenCascade:0x7fac3680a4f0 {}>

But if you set a node, then that will be it‘s value.

  c.a.b = 4             #=> 4

To query a node without causing the auto-creation of an OpenCasade object, use the ?-mark.

  c.a.z?                #=> nil

Finally, you can set a node and get the reciever back using the !-mark.

  c = OpenCascade.new   #=> #<OpenCascade:0x7fac3680ccf0 {}>
  c.x!(4).y!(3)         #=> #<OpenCascade:0x7fac3680ccf0 {:x=>4, :y=>3}>

Methods

Public Instance methods

[Source]

    # File lib/more/facets/opencascade.rb, line 70
70:   def method_missing( sym, arg=nil )
71:     type = sym.to_s[-1,1]
72:     name = sym.to_s.gsub(/[=!?]$/, '').to_sym
73:     if type == '='
74:       self[name] = arg
75:     elsif type == '!'
76:       self[name] = arg
77:       self
78:     elsif type == '?'
79:       self[name]
80:     else
81:       if val = self[name]
82:         if Hash === val
83:           self[name] = self.class.new(val)
84:         else
85:           self[name]
86:         end
87:       else
88:         self[name] = self.class.new
89:       end
90:     end
91:   end

[Validate]