Sha256: f8d31c29bd9372e927466312ac1526165f829081bb1defdd6e73c72416aaaac3

Contents?: true

Size: 605 Bytes

Versions: 3

Compression:

Stored size: 605 Bytes

Contents

module ActiveSupportMethods
  def camelize
    sub(/^([a-z])/) {$1.upcase}.gsub(/_([a-z])/) do
      $1.upcase
    end
  end
end
String.send :include, ActiveSupportMethods unless String.new.respond_to?(:underscore)

class String
  # inspired by http://github.com/rails/rails/blob/b600bf2cd728c90d50cc34456c944b2dfefe8c8d/activesupport/lib/active_support/inflector.rb
  def snake_case(seperator = '/')
    string = seperator == '::' ? dup : gsub(/::/, '/')
    string.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    string.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
    string.tr!("-", "_")
    string.downcase
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
couch_potato-0.2.30 lib/core_ext/string.rb
couch_potato-0.2.29 lib/core_ext/string.rb
couch_potato-0.2.28 lib/core_ext/string.rb