From: Jason Voegele Date: 2002-04-19T04:26:21+09:00 Subject: Re: Object#send with $SAFE >= 1 Paul Brannan wrote: > On Fri, Apr 19, 2002 at 04:10:42AM +0900, Jason Voegele wrote: >> Is there any way to call a method by name with $SAFE >= 1? > > AFAIK, #send does not use #eval. It also works with $SAFE == 1: > > irb(main):001:0> $SAFE = 1 > 1 > irb(main):002:0> class Foo; def foo; puts "foo!"; end; end > nil > irb(main):003:0> f = Foo.new > # > irb(main):004:0> f.send(:foo) > foo! > nil Strange. I tried your example in irb and got following error. Perhaps my irb is broken? A bug in Ruby? ruby -v ruby 1.6.6 (2001-12-26) [i586-mswin32] irb(main):001:0> $SAFE = 1 1 irb(main):002:0> class Foo; def foo; puts "foo!"; end; end SecurityError: Insecure operation - eval from c:/dev/ruby/lib/ruby/1.6/irb/workspace.rb:80:in `eval' from c:/dev/ruby/lib/ruby/1.6/irb/workspace.rb:80:in `evaluate' from c:/dev/ruby/lib/ruby/1.6/irb.rb:141:in `eval_input' from c:/dev/ruby/lib/ruby/1.6/irb.rb:141:in `trace_in' from c:/dev/ruby/lib/ruby/1.6/irb.rb:141:in `eval_input' from c:/dev/ruby/lib/ruby/1.6/irb.rb:138:in `signal_status' from c:/dev/ruby/lib/ruby/1.6/irb.rb:138:in `eval_input' from c:/dev/ruby/lib/ruby/1.6/irb.rb:136:in `each_top_level_statement' from c:/dev/ruby/lib/ruby/1.6/irb/ruby-lex.rb:243:in `loop' from c:/dev/ruby/lib/ruby/1.6/irb/ruby-lex.rb:243:in `each_top_level_s tement' from c:/dev/ruby/lib/ruby/1.6/irb/ruby-lex.rb:216:in `catch' from c:/dev/ruby/lib/ruby/1.6/irb/ruby-lex.rb:216:in `each_top_level_s tement' from c:/dev/ruby/lib/ruby/1.6/irb.rb:136:in `eval_input' from c:/dev/ruby/lib/ruby/1.6/irb.rb:68:in `start' from c:/dev/ruby/lib/ruby/1.6/irb.rb:67:in `catch' from c:/dev/ruby/lib/ruby/1.6/irb.rb:67:in `start' from c:\dev\ruby\bin\irb:13Maybe IRB bug!! -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Shadow of the Torturer