Sha256: 238ee2b38a2e2bafff041b4722d1e352c8662ee42d13eb7a2bd1c557f7d3967e

Contents?: true

Size: 474 Bytes

Versions: 40

Compression:

Stored size: 474 Bytes

Contents

module Underscorable
  # Port from activesupport-4.2.7.1/lib/active_support/inflector/methods.rb
  def underscore
    return self unless self =~ /[A-Z-]|::/
    word = self.to_s.gsub(/::/, '/')
    word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" }
    word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
    word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
    word.tr!("-", "_")
    word.downcase!
    word
  end
end

String.include Underscorable

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
junoser-0.6.0 lib/underscorable.rb
junoser-0.5.6 lib/underscorable.rb
junoser-0.5.5 lib/underscorable.rb
junoser-0.5.4 lib/underscorable.rb
junoser-0.5.3 lib/underscorable.rb
junoser-0.5.2 lib/underscorable.rb
junoser-0.5.1 lib/underscorable.rb
junoser-0.5.0 lib/underscorable.rb
junoser-0.4.7 lib/underscorable.rb
junoser-0.4.6 lib/underscorable.rb
junoser-0.4.5 lib/underscorable.rb
junoser-0.4.4 lib/underscorable.rb
junoser-0.4.3 lib/underscorable.rb
junoser-0.4.2 lib/underscorable.rb
junoser-0.4.1 lib/underscorable.rb
junoser-0.4.0 lib/underscorable.rb
junoser-0.3.13 lib/underscorable.rb
junoser-0.3.12 lib/underscorable.rb
junoser-0.3.11 lib/underscorable.rb
junoser-0.3.10 lib/underscorable.rb