Module: FatCore::Symbol

Included in:
Symbol
Defined in:
lib/fat_core/symbol.rb

Instance Method Summary collapse

Instance Method Details

#as_strObject

Convert this symbol to a string in such a manner that for simple cases, it is the inverse of String#as_sym and vice-versa.



32
33
34
35
36
37
38
# File 'lib/fat_core/symbol.rb', line 32

def as_str
  to_s
    .downcase
    .tr('_', '-')
    .gsub(/\s+/, '_')
    .gsub(/[^-_A-Za-z0-9]/, '')
end

#as_symSymbol

Return self in a form suitable as an identifier. Ruby allows symbols to have arbitrary characters in them that are not permitted as an identifier. Convert this symbol to one that is a legal identifier. This (together with String#as_sym) allows #as_sym to be applied to a string or Symbol and get back a Symbol with out testing for type.

Returns:



26
27
28
# File 'lib/fat_core/symbol.rb', line 26

def as_sym
  as_str.as_sym
end

#entitleString

Convert to a title-ized string, that is, convert all '_' to a space, then call String#entitle on the result.

Examples:

:hello_world.entitle #=> "Hello World"
:joy_to_the_world #=> 'Joy to the World'

Returns:



15
16
17
# File 'lib/fat_core/symbol.rb', line 15

def entitle
  to_s.tr('_', ' ').split.join(' ').entitle
end

#tex_quoteString

Prepare this symbol for use in a TeX document by converting to String then quoting it.

Examples:

:hammer_smith.tex_quote  #=> "hammer\\_smith"

Returns:



47
48
49
# File 'lib/fat_core/symbol.rb', line 47

def tex_quote
  to_s.tex_quote
end