From: Joel VanderWerf Date: 2002-02-19T06:05:44+09:00 Subject: Re: alias danger Joel VanderWerf wrote: > Isn't there some way (perhaps in 1.7?) of getting a copy of M's > implementation of foo as a Proc and redefining foo in terms of a closure > that refers to this proc? That way, instead of using alias, you'd be > able to use a local binding that couldn't affect anyone else. Found it in RiaN: Module#instance_method. This solves half of the problem: module M def foo p "foo" end end class C; include M; end c = C.new module M Unbound_foo = instance_method :foo def foo p "foo1" Unbound_foo.bind(self).call end end c.foo # ==> "foo1" # "foo" The other half of the problem would be solved if you could use a local var instead of a constant, and capture it in a closure. Is there something in 1.7 like this? module M unbound_foo = instance_method :foo define_method :foo { p "foo1" unbound_foo.bind(self).call } end The intent isn't as clear as with alias, but it is certainly safe. -- Joel VanderWerf California PATH, UC Berkeley mailto:vjoel@path.berkeley.edu Ph. (510) 231-9446 http://www.path.berkeley.edu FAX (510) 231-9512