Method: FatCore::String#as_sym

Defined in:
lib/fat_core/string.rb

#as_symSymbol

Convert to a lower-case symbol with all white space converted to a single '_' and all non-alphanumerics deleted, such that the string will work as an unquoted Symbol.

Examples:

"Hello World" -> :hello_world
"Hello*+World" -> :helloworld

Returns:

  • (Symbol)

    self converted to a Symbol


31
32
33
34
35
36
# File 'lib/fat_core/string.rb', line 31

def as_sym
  clean
    .gsub(/\s+/, '_')
    .gsub(/[^_A-Za-z0-9]/, '')
    .downcase.to_sym
end