[#964] Bastion or SecurityManager for Ruby? — Clemens Hintze <clemens.hintze@...>

Hi,

15 messages 1999/12/10

[#989] a question about to_i — Friedrich Dominicus <Friedrich.Dominicus@...>

Sorry, I'm quite new to ruby. But I encounterd the following problem. If

17 messages 1999/12/19

[ruby-talk:01013] Re: Reparenting a block

From: matz@... (Yukihiro Matsumoto)
Date: 1999-12-31 08:09:25 UTC
List: ruby-talk #1013
In message "[ruby-talk:01009] Reparenting a block"
    on 99/12/31, Dave Thomas <Dave@thomases.com> writes:

|Another block question. Is there any way to re-parent a Proc?

An Block has the bindings at the point where it appear, including
self, local variables, constant bindings, etc.  You can alternate self
in the block bindings by using instance_eval(), as Masaki stated in
[ruby-talk:01010].  Other than self, you can alter constant binding by
using class_eval()/module_eval().

  def foo(&block)
    Math.module_eval(&block)
  end

  foo {print PI}        # 3.141592654
  print PI              # NameError!

self and constant bindings are only modifiable bindings in the block.
You cannot alter other bindings.

Ruby/Tk is using this technics.

  TkButton::new(parent) {
     label "hello world"
     command { exit }
  }

invokes methods of a newly created TkButton object.  But it may be the
cause of confusion, e.g.

  Dave::new {
    @answer = 42  # modify Dave's instance variable.
  }
  print @answer   # @answer is not set here.

Hope this helps you in new millennium. :-)
Happy new year.

							matz.

In This Thread