Sha256: 5f7773b72fdbc7127eaff0cd918ec60d62f0f24d4365dd74913d30723176d226

Contents?: true

Size: 618 Bytes

Versions: 4

Compression:

Stored size: 618 Bytes

Contents

class String
  # taken from active-support
  def underscore
    gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
  end

  def camelize
    gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  end
end

unless defined?(TEST_ETEST)
  
  module String::Etest
    def test_camelize
      assert_equal "x", "X".underscore
      assert_equal "xa_la_nder", "XaLaNder".underscore
    end

    def test_underscore
      assert_equal "X", "x".camelize
      assert_equal "XaLaNder", "xa_la_nder".camelize
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
etest-0.4.2 lib/string_ext.rb
etest-0.4.1 lib/string_ext.rb
etest-0.4 lib/string_ext.rb
etest-0.3.1 lib/string_ext.rb