lib/facet/string/camelize.rb in facets-0.9.0 vs lib/facet/string/camelize.rb in facets-1.0.0

- old
+ new

@@ -1,34 +1,68 @@ -require 'nano/string/camelize.rb' \ No newline at end of file + +class String + + # Variation of coverting a string to camelcase. This is unlike + # #camelcase in that it is geared toward code reflection use. + # + # "this/is_a_test".camelize #=> This::IsATest + # + def camelize + #to_s.gsub(/(^|_)(.)/){$2.upcase} + to_s.gsub(/\/(.?)/){ "::" + $1.upcase }.gsub(/(^|_)(.)/){ $2.upcase } + end + +end + + +# _____ _ +# |_ _|__ ___| |_ +# | |/ _ \/ __| __| +# | | __/\__ \ |_ +# |_|\___||___/\__| +# +=begin test + + require 'test/unit' + + class TCString < Test::Unit::TestCase + + def test_camelize + assert_equal( 'ThisIsIt', 'this_is_it'.camelize ) + end + + end + +=end