Ruby 1.8: NoMethodError: undefined method `ord’ for "":String

Missing String#ord in Ruby 1.8? Here’s a simple monkey-patch that will add it to Ruby.

unless "".respond_to?(:ord)
  class String
    def ord
      self[0].ord
    end
  end
end

http://gist.github.com/251465

This entry was posted in Programming, Ruby. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>