On Wed, Nov 7, 2012 at 5:12 AM, 7stud -- <[email protected]> wrote:
> > By changing the fields of m, the applet can then change the Security
> Manager,
> > even though the Security Manager's fields have been declared private.
>
>
>
> class Dog
> def initialize
> @secret = 10
> end
> end
>
> d = Dog.new
> puts d.instance_eval("@secret")
>
> --output:--
> 10
>
> d.instance_eval("@secret = 20")
> puts d.instance_eval("@secret")
>
> --output:--
> 20
>
Since eval is evil there's also
irb(main):006:0> d=Dog.new
=> #<Dog:0x802e9c64 @secret=10>
irb(main):007:0> d.instance_variable_get '@secret'
=> 10
irb(main):008:0> d.instance_variable_set '@secret', 20
=> 20
irb(main):009:0> d.instance_variable_get '@secret'
=> 20
irb(main):010:0> d.instance_variables
=> [:@secret]
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en