Module: CSL::Treelike::ClassMethods

Defined in:
lib/csl/treelike.rb

Instance Method Summary collapse

Instance Method Details

#constantize_nodename(name) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
# File 'lib/csl/treelike.rb', line 279

def constantize_nodename(name)
  return constantize(name) if respond_to?(:constantize)

  klass = name.to_s.capitalize.gsub(/(\w)-(\w)/) { [$1, $2.upcase].join }

  if const_defined?(klass)
    const_get(klass)
  else
    nil
  end
end

#create_childrenObject

Returns a new instance of an Array or Struct to manage the Node’s children. This method is called automatically by the Node’s constructor.



271
272
273
274
275
276
277
# File 'lib/csl/treelike.rb', line 271

def create_children
  if const?(:Children)
    const_get(:Children).new
  else
    []
  end
end