Module: Eco::Language::Klass::Naming
- Included in:
- Builder, HelpersBuilt, InheritableClassVars
- Defined in:
- lib/eco/language/klass/naming.rb
Instance Method Summary collapse
-
#instance_variable_name(name) ⇒ Object
Helper to create an instance variable
name. -
#to_constant(key) ⇒ String
Helper to normalize
keyinto a correctrubyconstant name.
Instance Method Details
#instance_variable_name(name) ⇒ Object
Helper to create an instance variable name
18 19 20 21 22 |
# File 'lib/eco/language/klass/naming.rb', line 18 def instance_variable_name(name) str = name.to_s str = "@#{str}" unless str.start_with?("@") str end |
#to_constant(key) ⇒ String
Note:
it removes namespace syntax ::
Helper to normalize key into a correct ruby constant name
7 8 9 10 11 12 13 |
# File 'lib/eco/language/klass/naming.rb', line 7 def to_constant(key) key.to_s.strip.split('::').compact.map do |str| str.slice(0).upcase + str[1..]&.downcase end.join.split(/[\-\_ :]+/i).compact.map do |str| str.slice(0).upcase + str[1..]&.downcase end.join end |