Skip to content

Instantly share code, notes, and snippets.

@bri3d
Created May 23, 2013 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bri3d/5639849 to your computer and use it in GitHub Desktop.
Save bri3d/5639849 to your computer and use it in GitHub Desktop.
Encoding getting lost through Symbol conversion in send (JRuby 1.7.x)
# encoding: utf-8
nyay = "ñ"
puts "Source string's encoding is #{nyay.encoding}"
class TestDispatch
def method_missing(name, *args)
puts "Sent name is a #{name.class.inspect} with encoding #{name.encoding}"
puts "Sent name as a string is #{name}"
end
end
t = TestDispatch.new
puts "Sending source string as string"
t.send(nyay)
puts "Sending source string as symbol"
t.send(nyay.to_sym)
=begin
JRuby 1.7.4, -Dfile.encoding=UTF8
Oracle JDK7u15, 64-bit server
Locale en_US.UTF-8; reproduce on OSX and Ubuntu.
Output:
Source string's encoding is UTF-8
Sending source string as string
Sent name is a Symbol with encoding US-ASCII
Sent name as a string is ?
Sending source string as symbol
Sent name is a Symbol with encoding UTF-8
Sent name as a string is ñ
Ruby 1.9.3, OSX (reference/desired result):
Source string's encoding is UTF-8
Sending source string as string
Sent name is a Symbol with encoding UTF-8
Sent name as a string is ñ
Sending source string as symbol
Sent name is a Symbol with encoding UTF-8
Sent name as a string is ñ
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment