[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Is better to subclass or to add methods to an existing class?
From: "Christoph" <chr_news () gmx ! net>
Date: 2002-09-19 22:38:40
[Download RAW message or body]
"Paul Brannan" <pbrannan@atdesk.com> wrote in message news:20020919172550.F6781@atdesk.com...
> On Fri, Sep 20, 2002 at 05:41:58AM +0900, Christoph wrote:
> > Beast = self
> > (@temptation = Class.new String).class_eval <<-Body
> > Beast = self
> > def six_six_six; Beast end
> > Body
>
> What's wrong with:
>
> Beast = self
> (@temptation = Class.new String).class_eval do
> Beast = self
> def six_six_six; Beast end
> end
(In 1.7 one can also use Class.new super_class { .. } )
``proc type'' class_eval's do not change the scope. In other
words there is only one (the top) Beast around - hence
p six_six_six # =>
#<Object:0x1011b550 @temptation=#<Class:0x1010a7f8>>
A ``string type'' class_eval creates the expected two
Beasts and six_sx_six picks up the inner Beast - hence
p six_six_six # =>
#<Class:0x1010c388>
/Christoph
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic