Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/tu-context/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#to_class_nameObject

Borrowed from camelize in ActiveSupport



14
15
16
# File 'lib/tu-context/core_ext/string.rb', line 14

def to_class_name
  self.to_method_name.gsub(/\/(.?)/) { "#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end

#to_method_nameObject

Replaces spaces and tabs with _ so we can use the string as a method name Also replace dangerous punctuation



4
5
6
# File 'lib/tu-context/core_ext/string.rb', line 4

def to_method_name
  self.downcase.gsub(/[\s:',\.~;!#=\(\)&\?]+/, '_')
end

#to_module_nameObject

Borrowed from camelize in ActiveSupport



9
10
11
# File 'lib/tu-context/core_ext/string.rb', line 9

def to_module_name
  self.to_method_name.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end