Module: FatCore::Symbol
- Included in:
- Symbol
- Defined in:
- lib/fat_core/symbol.rb
Instance Method Summary collapse
-
#as_str ⇒ Object
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.
-
#as_sym ⇒ Symbol
Return self in a form suitable as an identifier.
-
#entitle ⇒ String
Convert to a title-ized string, that is, convert all '_' to a space, then call String#entitle on the result.
-
#tex_quote ⇒ String
Prepare this symbol for use in a TeX document by converting to String then quoting it.
Instance Method Details
#as_str ⇒ Object
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_sym ⇒ Symbol
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.
26 27 28 |
# File 'lib/fat_core/symbol.rb', line 26 def as_sym as_str.as_sym end |