Skip to content

Instantly share code, notes, and snippets.

@momo-lab
Created June 27, 2012 00:51
Show Gist options
  • Save momo-lab/3000522 to your computer and use it in GitHub Desktop.
Save momo-lab/3000522 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -Ku
require 'nkf'
class String
def printable!
self.each_char.find_all{|ch| NKF.guess(ch) == NKF::UTF8}.join("")
end
end
require 'test/unit'
class PrintableTest < Test::Unit::TestCase
def test_printable
assert_equal "あいえお", "あ\000い\343う\201え\202お".printable!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment