Never been to DZone Snippets before?

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

About this user

JavaScript Wizard

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

UTF-8 compatible String ranges in Ruby

As found at http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/123935

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
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS