(2011/11/28 17:43), Michel Demazure wrote:
> Matz wrote : 
>> a = :foo
>> p a.encoding      # => #<Encoding:US-ASCII>  (a)

A symbol which consists of only US-ASCII characters is US-ASCII.

>> b = "foo"
>> p b.encoding      # => #<Encoding:UTF-8>     (b)

Of course, it is UTF-8.

>> c = "#{a}foo"
>> p c.encoding	  # => #<Encoding:US-ASCII>  (c)

(str + another)'s encoding will be str's encoding when both str and
another consist of only ASCII characters.

>> d = "foo#{a}"
>> p d.encoding      # => #<Encoding:UTF-8>     (d)

So this is "foo"'s encoding.

>> (a) and (b), (c) and (d) are inconsistent.
> 
> Yes, but suppose you have the same symbol :sym occurring in two source files
> with distinct encodings.

If they consist of ASCII characters, they are identical.
If they include non ASCII characters, they have distinct encoding and
are treated as different symbols.

> Then, can :sym.to_s have two values depending on
> the file in which it is used ?

Did you try it?

-- 
NARUSE, Yui  <naruse / airemix.jp>