4

In ruby 1.8.7, what determines what the encoding of File#path will be? The filesystem? A configuration somewhere? The encoding of each individual file?

I've seen two different encodings in otherwise identical environments on different OS's.

Related question: Reading filename in multiple OS without encoding problem with Ruby

update

I guess I need to set/know the encoding of the filesystem... this does not help though (unless I'm putting it in the wrong place)...

export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
Community
  • 1
  • 1
John Bachir
  • 22,495
  • 29
  • 154
  • 227
  • I don't know of a method `File#name`. Which module contains this? It's neither in the Ruby 1.8.7 core nor in the _fileutils_ module. – Niklas B. Sep 01 '11 at 09:09
  • whoops! tired brain... `File#path`... fixed now – John Bachir Sep 01 '11 at 14:31
  • It semms to return the raw byte string received from the FS. To interpret it properly, you need to know the encoding of the filesystem and for example use iconv to translate it (as shown in the post you pointed at) – Niklas B. Sep 01 '11 at 14:39

1 Answers1

1

Theoratically you can read the system's encoding from

ENV['LC_LANG']

and you can set it the same way for the ruby script:

ENV['LC_LANG']=en_US.UTF-8

Same goes for the other encoding specific environment variables.

Aurril
  • 2,469
  • 2
  • 24
  • 38
  • This is really theoretic, because there is more behind this (users usually sets LC_ALL, LC_COLLATE and other things). – lzap Jan 23 '13 at 14:15