Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created January 28, 2009 05:36
Show Gist options
  • Save maraigue/53835 to your computer and use it in GitHub Desktop.
Save maraigue/53835 to your computer and use it in GitHub Desktop.
Ruby1.9勉強中:URLエンコード
#!/usr/bin/env ruby1.9
# -*- coding: utf-8 -*-
def URLencode(str)
str.force_encoding("binary").gsub(/\W+/){ |x| x.unpack("C*").map{ |y| sprintf("%%%02X", y) }.join }
end
puts URLencode("ほげ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment