Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string.rb

Instance Method Summary collapse

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_sqlObject

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