On 2/15/07, sur max <sur.max / gmail.com> wrote:
> hey guys !!
> pls explain the meaning of Singleton Class
> my perception is that it can only be associated with a single object, and
> thats why its name so.
> If you really wanna create more objects then isnt it better to redefine the
> class with new functions.

Sorry to bore you , if you are already aware of this:

In Ruby when you add methods to an obj like this:

class << obj
  def foobar; end
end

it creates a Singleton/Virtual class for that object, if singleton
class exists for that object, it would simply add method "foobar" to
that.  So basically, Steve wants to copy this singleton class
associated with obj to the new class. Although its not clear to me,
how that would enable him to dynamically change the underlying
ActiveRecord table.

However, what puzzles me, how come #clone copies methods from
Singleton class as well? #dup won't allow that. You can't marshal
singleton and an attempt would throw error.

As usual Ara's solution seems best, but if faced with similar
situation I would probably also consider Delegator pattern.


> what say ?
>
> On 2/15/07, Jimmy Kofler <koflerjim / mailinator.com> wrote:
> >
> > > Posted by Steve Midgley (stevemidgley) on 14.02.2007 20:24
> > > ...
> > > Now what I really want is to create a second instance of the newly
> > > created singleton class. It appears to be impossible. A guess the name
> > > singleton implies as much. But with all of Ruby's tricks, I thought
> > > there'd be a way to create a new instance of a singleton.. Probably
> > > there is but I don't see it.
> > > ...
> >
> > Maybe also check out http://www.ruby-forum.com/topic/94696
> >
> > Regards
> > JK
> >
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> >
> >
>
>
> --
> sur
> http://expressica.com
>


-- 
gnufied
-----------
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.
http://people.inxsasia.com/~hemant