From: mdiam <Maurice.Diamantini / gmail.com> Subject: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1) Date: Tue, 6 Jan 2009 18:15:01 +0900 Message-ID: <dca4d3eb-f842-48cb-9627-f9f0231ded13 / r37g2000prr.googlegroups.com> > I have a script starting like this : > > #!/usr/bin/env ruby > # encoding: iso8859-1 > > When I lauch it, the following error occurs: I can't regenerate the error. > .../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3028:in `find': > unknown encoding name - (ArgumentError) > from /.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3028:in `<top (required)>' Probably, the error occurs on Encoding.find(), but tk.rb:3028 doesn't include the method. On my archive, tk.rb:3028 is a comment line. Please check your '.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb' file. tk.rb included ruby-1.9.1-rc1 has the following line (line:5553). ------------------------------------------------------ RELEASE_DATE = '2008-12-21'.freeze ------------------------------------------------------ > Also, is there any online doc on all the encoding feature from > ruby-1.9.1??? Not all, but about Ruby/Tk, its default rules are the followings. * Use Encoding.default_external for terminal outputs of Tcl/Tk libraries. It can be referd/changed with Tk.encoding_system/encoding_system=. * Use Encoding.default_internal for strings passed from Tcl/Tk libraries to Ruby. It can be referd/changed with Tk.encoding/encoding=. However, if the constant DEFAULT_TK_ENCODING is defined before 'require "tk"', Ruby/Tk use it instead of Encoding.default_internal. If DEFAULT_TK_ENCODING is not defined and Encoding.default_internal is nil, use Encoding.default_external. It may be better that Ruby/Tk returns strings by caller's script encoding. But, if I'm right, libraries (e.g. tk.rb) can't know caller's script encoding (at least, by low cost). So, Ruby/Tk supports the global status (Tk.encoding) only. Well, you can get current script encoding by __ENCODING__. If you want to use it for Ruby/Tk, for example, ------------------------------------------------------ DEFAULT_TK_ENCODING = __ENCODING__ require 'tk' ------------------------------------------------------ or ------------------------------------------------------ require 'tk' Tk.encoding = __ENCODING__ ------------------------------------------------------ -- Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)