Class: String

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

Instance Method Summary collapse

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

Returns:

  • (Boolean)


246
247
248
# File 'lib/sinatra/rabbit.rb', line 246

def blank?
    self !~ /\S/
end

#pluralizeObject



261
262
263
# File 'lib/sinatra/rabbit.rb', line 261

def pluralize
  self + "s"
end

#singularizeObject



265
266
267
# File 'lib/sinatra/rabbit.rb', line 265

def singularize
  self.gsub(/s$/, '')
end

#titlecaseObject

Title case.

"this is a string".titlecase
=> "This Is A String"

CREDIT: Eliazar Parra Copied from facets



257
258
259
# File 'lib/sinatra/rabbit.rb', line 257

def titlecase
  gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
end

#underscoreObject



269
270
271
272
273
274
275
# File 'lib/sinatra/rabbit.rb', line 269

def underscore
    gsub(/::/, '/').
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        tr("-", "_").
        downcase
end