Sha256: d0cbada505a850e861c58b021b0ee88a492f18da70e8ddecf57d99bed42c4ada

Contents?: true

Size: 1.59 KB

Versions: 51

Compression:

Stored size: 1.59 KB

Contents

class String
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
  def camelize(first_letter = :upper) 
    if first_letter == :upper
      gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
    else
      self[0..0].downcase + camelize[1..-1]
    end
  end unless method_defined? :camelize

  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
  def constantize
    names = split('::')
    names.shift if names.empty? || names.first.empty?
  
    constant = Object
    names.each do |name|
      constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
    end
    constant
  end unless method_defined? :constantize
  
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
  def dasherize
    gsub(/_/, '-')
  end unless method_defined? :dasherize
  
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
  def demodulize
    gsub(/^.*::/, '')
  end unless method_defined? :demodulize

  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
  def underscore
    gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
  end unless method_defined? :underscore
  
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
backports-3.0.3 lib/backports/rails/string.rb
backports-3.0.2 lib/backports/rails/string.rb
backports-3.0.1 lib/backports/rails/string.rb
backports-3.0.0 lib/backports/rails/string.rb
backports-2.8.2 lib/backports/rails/string.rb
backports-2.8.1 lib/backports/rails/string.rb
backports-2.8.0 lib/backports/rails/string.rb
backports-2.7.1 lib/backports/rails/string.rb
backports-2.7.0 lib/backports/rails/string.rb
backports-2.6.7 lib/backports/rails/string.rb
backports-2.6.6 lib/backports/rails/string.rb
backports-2.6.5 lib/backports/rails/string.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/backports-2.6.4/lib/backports/rails/string.rb
backports-2.6.4 lib/backports/rails/string.rb
backports-2.6.3 lib/backports/rails/string.rb
backports-2.6.2 lib/backports/rails/string.rb
backports-2.6.1 lib/backports/rails/string.rb
backports-2.6.0 lib/backports/rails/string.rb
backports-2.5.3 lib/backports/rails/string.rb
backports-2.5.2 lib/backports/rails/string.rb