[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:       Paul Brannan <pbrannan () atdesk ! com>
Date:       2002-09-19 16:48:29
[Download RAW message or body]

On Fri, Sep 20, 2002 at 01:20:37AM +0900, William Djaja Tjokroaminata wrote:
> Actually, because in Ruby a class definition is never closed, don't we
> fundamentally have a similar problem (although possibly with much less
> probability, especially when module is used) by subclassing as adding a
> method?  In other words, the name of subclass that we create may already
> be used as a name of some other class.

You can create the subclass inside a "namespace", e.g.:

  module MyProject
    class String < ::String
      ...
    end
  end

You can also create an anonymous subclass:

  class Foo
    @@my_string = Class.new(String)
  end

Paul

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic