Travis Smith
3/22/2005 1:24:00 PM
Turns out the reason it didn't work at all for me was that my class
was being defined with 'def' instead of 'class'. Silly how typos break
everything...
That's very similar to what I have working now though the @instances
is stored in another class and I truncate the filenames (remove the
rb). I have a class which I 'ask' for the instance I want and if it
doesn't exist it will go out and load it. I think keeping the list of
objects inside the class might be better than my current method...
Well, now I have more to play with. We'll see where takes me. Thanks
On Tue, 22 Mar 2005 16:49:51 +0900, Robert Klemme <bob.news@gmx.net> wrote:
>
> "Travis Smith" <zultan.durin@gmail.com> schrieb im Newsbeitrag
> news:d95bacd905032121284d8f756b@mail.gmail.com...
> > Say I have a class Here, and I loaded that class from some file
> > outside my driver via require. So now the class Here is in my
> > namespace and I can create a new one with Here.new. What I would like
> > to do is create a singleton of the same class with information stored
> > in another ruby file. That file would contain something like this....
> >
> > class Here
> > def initialize
> > @var1 = "something else"
> > end
> >
> > # adding a method that isn't part of the normal Here class
> > def new_method
> > # do something
> > end
> > end
> >
> > Now, I could just create the singleton and store it somewhere for when
> > I needed it, but I plan on having a number of these. Each of them in
> > their own file. I thought perhaps I would need to add a line of code
> > to the end of the to store that singleton where I needed it. This
> > really didn't end up working for me. It would just use the global
> > class when I would load the file via load _filename_, false.
> >
> > What I would really like is just some way to turn a file into an
> > anonymous class and be able to initialize it just as is. I'm not sure
> > if that's easily possible though.
>
> Have a look at the attached files and see whether that helps you.
>
> > Thanks for any ideas here. I've only been on Ruby for four days now,
> > but it's been pretty easy to get this far.
>
> :-)
>
> Kind regards
>
> robert
--
~Travis