Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Instance Method Summary collapse
-
#as(alias_name) ⇒ Object
call-seq: string.as(alias_name) -> a_symbol.
-
#to_sql ⇒ Object
call-seq: string.to_sql -> a_string.
Instance Method Details
#as(alias_name) ⇒ Object
call-seq: string.as(alias_name) -> a_symbol
Returns the string aliased (including ‘as’) as the aliased name
"book".as(:category) #=> :"'book' as category"
16 17 18 |
# File 'lib/string.rb', line 16 def as(alias_name) "#{self.to_sql} as #{alias_name}".to_sym end |
#to_sql ⇒ Object
call-seq: string.to_sql -> a_string
Returns a string with single quotes escaped.
:book.to_sql #=> "book"
7 8 9 |
# File 'lib/string.rb', line 7 def to_sql "'#{self.gsub(/'/, "''")}'" end |