Class: CodeTree::Name2X::ModuleDelegate

Inherits:
Delegate
  • Object
show all
Defined in:
lib/sbyc/codetree/name2x/module_delegate.rb

Instance Attribute Summary

Attributes inherited from Delegate

#delegate

Instance Method Summary collapse

Methods inherited from Delegate

coerce, #initialize, #name2class, #name2module

Constructor Details

This class inherits a constructor from CodeTree::Name2X::Delegate

Instance Method Details

#fetch(name) ⇒ Object

Overrides the default behavior to use const_get instead.



6
7
8
9
10
11
# File 'lib/sbyc/codetree/name2x/module_delegate.rb', line 6

def fetch(name)
  name = name2name(name)
  delegate.const_defined?(name) ? delegate.const_get(name) : nil
rescue NameError
  nil
end

#name2name(name) ⇒ Object

Capitalize a name



14
15
16
17
18
19
20
# File 'lib/sbyc/codetree/name2x/module_delegate.rb', line 14

def name2name(name)
  src = name.to_s
  src.gsub!(/[^a-zA-Z\s]/," ")
  src = " " + src.split.join(" ")
  src.gsub!(/ (.)/) { $1.upcase }    
  src.to_sym
end