Class: OpenCascade

Inherits:
OpenObject show all
Defined in:
lib/more/facets/opencascade.rb

Overview

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 trandformed 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

– Last, when an entry is not found, ‘null’ is returned rather then ‘nil’. This allows for run-on entries withuot error. Eg.

o = OpenCascade.new
o.a.b.c  #=> null

Unfortuately this requires an explict test for of nil? in ‘if’ conditions,

if o.a.b.c.null?  # True if null
if o.a.b.c.nil?   # True if nil or null
if o.a.b.c.not?   # True if nil or null or false

So be sure to take that into account. ++

Constant Summary

Constants inherited from OpenObject

OpenObject::PUBLIC_METHODS

Instance Method Summary collapse

Methods inherited from OpenObject

#==, #[], [], #[]=, #as_hash!, #default!, #delete, #each, #initialize, #initialize_copy, #inspect, #merge, #to_a, #to_h, #to_hash, #to_openobject, #to_proc, #update

Methods inherited from Hash

#&, #*, #+, #-, #<<, #alias!, #argumentize, autonew, #delete_unless, #delete_values, #delete_values_at, #diff, #each_with_key, #except, #except!, #has_keys?, #has_only_keys?, #insert, #inverse, #join, #mash!, #normalize_keys, #normalize_keys!, #pairs_at, #rand_key, #rand_key!, #rand_pair, #rand_pair!, #rand_value, #rand_value!, #rekey, #rekey!, #replace_each, #restore_snapshot, #reverse_merge, #reverse_merge!, #select!, #shuffle, #shuffle!, #slice, #slice!, #stringify_keys, #stringify_keys!, #swap!, #swapkey!, #symbolize_keys, #symbolize_keys!, #take_snapshot, #to_console, #to_h, #to_openobject, #to_ostruct, #to_ostruct_recurse, #to_proc, #to_proc_with_reponse, #to_struct, #traverse, #traverse!, #update_each, #update_keys, #update_values, #variablize_keys, #variablize_keys!, #weave, zipnew, #|

Constructor Details

This class inherits a constructor from OpenObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, arg = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/more/facets/opencascade.rb', line 76

def method_missing( sym, arg=nil )
  type = sym.to_s[-1,1]
  name = sym.to_s.gsub(/[=!?]$/, '').to_sym
  if type == '='
    self[name] = arg
  elsif type == '!'
    self[name] = arg
    self
  else
    val = self[name]
    val = object_class[val] if Hash === val
    val
  end
end