require 'facet/string/to_arr' require 'facet/enumerable/frequency' class String def frequency(*args) to_arr(*args).frequency end end #-- # NOTE: add String#occur and String#occur_within in future ? #++ # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCString < Test::Unit::TestCase def test_frequency assert_equal( {'a'=>1,'b'=>1}, "ab".frequency ) assert_equal( {'tom'=>1,'boy'=>1}, "tom boy".frequency(:word) ) assert_equal( {'tom'=>1,'boy'=>1}, "tom\nboy".frequency(:line) ) end end =end