Sha256: 3b9616f2cfefd8dc2d3e2e22cec6ff812b7bea472f57d9797c41e6218c8ffa85

Contents?: true

Size: 818 Bytes

Versions: 20

Compression:

Stored size: 818 Bytes

Contents

class String

  # Converts a string into a valid ruby method name
  # This method is geared toward code reflection.
  #
  #
  #   "MyModule::MyClass".methodize  #=> "my_module__my_class"
  #
  # See also String#modulize, String#pathize
  #
  # == TODO
  #
  # * Make sure that all scenarios return a valid ruby class name
  # * Make sure it is revertible
  #

  def methodize
    to_s.gsub(/([A-Z])/, '_\1').downcase.gsub(/^_/,'').gsub(/(::|\/)_?/, '__')
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCString < Test::Unit::TestCase

    def test_methodize
      assert_equal( 'hello_world', 'HelloWorld'.methodize )
      assert_equal( '__unix_path', '/unix_path'.methodize )
    end

  end

=end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
facets-1.3.0 lib/facets/core/string/methodize.rb
facets-1.3.3 lib/facets/core/string/methodize.rb
facets-1.3.1 lib/facets/core/string/methodize.rb
facets-1.3.2 lib/facets/core/string/methodize.rb
facets-1.4.1 lib/facets/core/string/methodize.rb
facets-1.4.2 lib/facets/core/string/methodize.rb
facets-1.4.0 lib/facets/core/string/methodize.rb
facets-1.4.3 lib/facets/core/string/methodize.rb
facets-1.4.5 lib/facets/core/string/methodize.rb
facets-1.4.4 lib/facets/core/string/methodize.rb
facets-1.7.30 lib/facets/core/string/methodize.rb
facets-1.7.0 lib/facets/core/string/methodize.rb
facets-1.7.38 lib/facets/core/string/methodize.rb
facets-1.7.46 lib/facets/core/string/methodize.rb
facets-1.8.0 lib/facets/core/string/methodize.rb
facets-1.8.49 lib/facets/core/string/methodize.rb
facets-1.8.20 lib/facets/core/string/methodize.rb
facets-1.8.51 lib/facets/core/string/methodize.rb
facets-1.8.8 lib/facets/core/string/methodize.rb
facets-1.8.54 lib/facets/core/string/methodize.rb