On Sunday 08 January 2006 06:14 pm, dblack / wobblini.net wrote:
> Hi --
>
> On Mon, 9 Jan 2006, Steve Litt wrote:
> > On Sunday 08 January 2006 05:04 pm, Gregory Brown wrote:
> >> On 1/8/06, Steve Litt <slitt / earthlink.net> wrote:
> >>> That's why I'm glad my electric stove has
> >>> lights saying which burners are still hot. And that's why I enjoy
> >>> programming in languages like Ruby, Python and Java, that protect me
> >>> from myself.
> >>
> >> Java:  Yes. (in the average scenario)
> >> Python:  Pretty much kinda maybe.
> >> Ruby: You'll shoot your eye out!  ;)
> >
> > Everyone says that, but I don't see it (til it hits me in the eye? :-).
> >
> > Maybe I'm just used to C, where the slightest mistake leads to a subtle
> > bug that happens every couple weeks.
> >
> > Sure, if I went out of my way I could make Ruby do corruptable things,
> > whereas with C I cannot avoid it.
> >
> > Ruby has beautiful encapsulation. Yeah it could be defeated, but you'd
> > really have to try. I want my language to protect me from my own
> > mistakes, not from my own death wish.
> >
> > Personally, I'd NEVER gratuitously add a method or instance var to a
> > class at runtime. If I needed more methods than the class provided, I'd
> > subclass it. I mean, how hard is it to subclass something, especially in
> > Ruby. Adding methods and instance variables to classes in real time
> > reminds me of senators who add a social security amendment to a defense
> > bill -- it's just bad business that can lead to no good.
>
> I'm not sure what you mean by adding an instance variable to a class,
> but as for methods, they're all defined at runtime.
>
>    class C
>      def m
>      end
>    end
>
> That code gets executed, and then there's a class called C with an
> instance method m.
>
> I'm not sure what it is that you consider subclassing to be a better
> choice than.  Are you talking about define_method?  Or the practice of
> reopening core classes?
>
>
> David

Hi David,

I don't know for sure, because when I read about this stuff my first reaction 
was "I'm not gonna do that!"

I got the impression I could do this:

myclass = MyClass.new
myclass.never_seen_before_attribute = 5

As I said, I didn't research it because I considered its use to be a negative, 
but stored it in the back of my mind in case I had to maintain code like 
that.

SteveT


-- 
Steve Litt
http://www.troubleshooters.com
slitt / troubleshooters.com