Austin Ziegler wrote:
>
> I'm not wanting to extrapolate. Consider me the conservative here,
> Trans. Convince me that this is really useful and important.

It's all relative Austin. How *really useful and important* is
anything? Most things can be done in some other way. But this much is
certain, there are things you CAN'T do b/c of this --or at least not
wihtout jumping through some magical hoops like defining a method
grabing the UnboundMethod, converting to_proc and undefining the method
(which I have done). But as to the example I was trying to show here...
here's something a little bit more real-to-life, though still off the
top of my head.

  dir = File.dirname(__FILE__)

  m = module.new do

    make_dir_method = lambda { |which, path|
      class_eval {
        define_method( "#{which}dir" ) { |name|
          dir = File.dirname(path)
          name = File.basename(path)
          File.join(dir,which,name)
        }
      }
    }

    make_dir_method('lib',dir)
    make_dir_method('var',dir)
    make_dir_method('bin',dir)

  end


> >> This isn't a closure problem. This is a constant lookup problem, and
> >> Matz has said that this should be fixed moving forward.
> > It has to do with closures in that the reference to constants is
> > relative to the given closure. So the current behavior is correct. A
> > non-closure block will allow the needed alternate behavior.
>
> Not by my understanding. Constant lookup is handled separately from
> closure rules, which mostly deals with local variables. That is to say
> that:
>
>   class X; end
>   Y = Class.new(X) do
>     X = Class.new do
> 	end
>   end
>
> is and should be different than:
>
>   class X; end
>
>   x = X
>   p x # X
>
>   Y = Class.new(X) do
>     x = Class.new do
> 	end
>  	const_set("X", x)
>   end
>
>   p x # Y::X
>
> Closure rules don't ahve anything to do with constant lookup, at least
> at this point.
  ^^^^^^^^^^^^^

Doesn't it seem just a little odd that this causes an error?

  class X
    Y = 1
  end

  X.class_eval { Y }

I know, I know. It makes total sense with how Ruby works. Not so sure
how Ruby works makes total sense.  Honestly, how can closure NOT be of
significant to constant lookup?

T.