Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/sinatra/rabbit.rb
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Rails defines this for a number of other classes, including Object see activesupport/lib/active_support/core_ext/object/blank.rb.
- #pluralize ⇒ Object
- #singularize ⇒ Object
-
#titlecase ⇒ Object
Title case.
- #underscore ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
Rails defines this for a number of other classes, including Object see activesupport/lib/active_support/core_ext/object/blank.rb
249 250 251 |
# File 'lib/sinatra/rabbit.rb', line 249 def blank? self !~ /\S/ end |
#pluralize ⇒ Object
264 265 266 |
# File 'lib/sinatra/rabbit.rb', line 264 def pluralize self + "s" end |
#singularize ⇒ Object
268 269 270 |
# File 'lib/sinatra/rabbit.rb', line 268 def singularize self.gsub(/s$/, '') end |
#titlecase ⇒ Object
Title case.
"this is a string".titlecase
=> "This Is A String"
CREDIT: Eliazar Parra Copied from facets
260 261 262 |
# File 'lib/sinatra/rabbit.rb', line 260 def titlecase gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase } end |
#underscore ⇒ Object
272 273 274 275 276 277 278 |
# File 'lib/sinatra/rabbit.rb', line 272 def underscore gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |