UTF-8 compatible String ranges in Ruby
class String def [] (*params) if params.all? { |p| Integer===p } || params.size==1 && Range===params[0] res = self.unpack("U*").[](*params) res = [res] unless Array===res return res.pack("U*") end super end end
DZone Snippets > jswizard > utf
11381 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
class String def [] (*params) if params.all? { |p| Integer===p } || params.size==1 && Range===params[0] res = self.unpack("U*").[](*params) res = [res] unless Array===res return res.pack("U*") end super end end