Module: Remotus::CoreExt::String

Included in:
String
Defined in:
lib/remotus/core_ext/string.rb

Overview

String extension module

Instance Method Summary collapse

Instance Method Details

#to_method_nameSymbol

Converts a string into a safe method name that can be used for instance variables

Returns:

  • (Symbol)

    Method name



14
15
16
17
18
19
20
21
# File 'lib/remotus/core_ext/string.rb', line 14

def to_method_name
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z])([A-Z])/, '\1_\2')
    .tr(" ", "_")
    .gsub(/(?:[^_a-zA-Z0-9]|^\d+)/, "")
    .downcase
    .to_sym
end