$SAFE inside an Array

Hi,

is this an intended behaviour or is it a bug? I did boil the
problem I detected down to the smallest possible code.

  class C
    t = Thread.new do
      $SAFE = 1
      def inspect
        "<C>"
      end
    end
    t.join
  end
  c = C.new
  puts c.inspect
  puts [c].inspect
  not_reached

The output is:

  <C>
  insecure.rb:12:in `inspect': calling insecure method: inspect (SecurityError)
          from insecure.rb:12:in `<main>'

Why is the first #inspect allowed, but the second is not?
Should I still use $SAFE at all?

Thanks in advance,

Bertram

···

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Hi,

···

On Tuesday, 14. Jul 2015, 22:07:32 +0200, Bertram Scharpf wrote:

  insecure.rb:12:in `inspect': calling insecure method: inspect (SecurityError)
          from insecure.rb:12:in `<main>'

I forgot to mention the version that produced the exception.

  $ ruby --version
  ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-freebsd10]

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de