On Thu, 18 Sep 2008, Joshua Choi wrote:
@Mr. Sasse:
"only"! I didn't know you could do that at all. In ruby a lowercase
name is just a method, but it may have nothing to do with any
particular
class.
Actually, what you're referring to here is tangent to the issue I'm
talking about, but I'll explain it.
This is a Shoes-specific thing: I found out about it in Mr. Why's
post
about custom widgets
(http://hackety.org/2008/06/12/martinDemellosGooeyChallenge.html).
When Shoes can't find a method, it apparently looks for a class with
Oh, right. OK.
the same name (case insensitive); if it finds one, it initializes it
with the method's arguments. For instance. Mr. Why created a
BorderButton class, and he initialized an BorderButton object with
the
method borderbutton. (Mr. Why probably did this to be consistent with
methods like button() and para(), which initialize classes like
Button
and Para.)
I never thought they were done by method_missing. Very nice.
Now, probably for speed purposes, he's apparently limited it to
Widget
subclasses only...but I may be mistaken.
I've looked at that pretty carefully and they look the same to me.
The difference is in the OKButton class's superclass. One is Button
(doesn't work now); the other is Widget. I correspondingly called
either super() or button() in the class's initialize() method.
Now you know why I hate proofreading! I see that now. :-)
How exactly did you do that? If your program was running, then the
initial shoes dialogue goes away, so you just have the interface you
wrote.
I'm not sure what the second sentence means, but that's probably my
ignorance. :) I think I can guess at your question (forgive me if you
already know the next part). In Mac OS X, Shoes runs as a single
Application, which opens Ruby and Shy files. A single running OS X
application hosts many Shoes programs. However, it seems like as long
as I don't actually quit from the Shoes application, programs'
classes
or something are saved—I'm guessing this because quitting the Shoes
application and relaunching it, then opening my own program in it,
gets rid of the superclass clash error and thus seems to "reset"
whatever it saved.
Ok. I've not tested running multiple shoes apps on Windows to be sure
it's the same. Yes, then it is probably the we-can-extend-classes bit
of ruby that is doing this.
Do you have the exact text of the error?
Here it is (I'll have to type this out—I wish it were possible to
select text in a Shoes program. :( )...
I've asked for that, too. The selection would get picked up by
Microsoft Narrator give speech access to the specific bits one
would wish. I don't know enough cairo to contribute, so I'll be
patient.
Error in /Applications/Shoes/..blah, blah.../lib/shoes.rb line 359
superclass mismatch for class OKButton
Ah, I've never seen that in ruby but I think it works like this
Classes begin with Capitals, so they are constants. The fact you
can change what is inside them doesn't matter. So it looks for the
constant and matches it but the superclass of the original doesn't
match.
Thus the original definition is still in memory. Can I prove that?
irb(main):001:0>
irb(main):002:0* class HP; end
=> nil
irb(main):003:0> class Compaq; end
=> nil
irb(main):004:0> class MyPC < Compaq ; end
=> nil
irb(main):005:0> # HP by compaq
irb(main):006:0*
irb(main):007:0* class MyPC < HP ; def id; puts self.class; end ; end
TypeError: superclass mismatch for class MyPC
from (irb):7
irb(main):008:0>
irb(main):009:0*
I fear that I'm poorly explaining this problem. Here's the deal: in
Mac OS X, Shoes runs as a single application. I keep it open all the
time when I program so that when I run my program, I can just switch
to it, instead of relaunching it and bringing up the console window
every time.
can't you put a
#!shoes
line in your shoes programs as we can in Windows? I don't even
bother with the full path to shoes for this, and as new build
get new subdirs.... I suppose I could point at the shoes.bat
that always lives at the top. Anyway, all the .rb files get marked
as being ruby, but ruby honours the #! line of scripts, so it
can even run Perl scripts correctly! That way you can just click
on the icon to run it.
However, when I edited a program by changing a class's superclass,
and
then ran it in Shoes, Shoes could not compile it. It raised the error
you see above. This made me suspect that Shoes keeps some sort of
data
as long as it's open to speed up future programs. However, it raises
the possibility of very surprising behavior to happen in the future,
like this error today.
And if it shares the memory between programs then one might have weird
effects.
class Tank
attr_accessor :fish, :plants, :shells
def needs_cleaning?
....
end
end
meanwhile...
class Tank
attr_accesor :shells, :soldiers
def aim(target)
....
end
end
You can supply your own fish puns at this point.
If a ruby program reads files with the same classes in, the classes
get extended. Yes, this can lead to problems.
Yes, and if this can lead to problems, then documentation is needed
on
how this persistence works in Shoes. I appeal to Mr. Why: could you
explain why this behavior is happening?
Thank you everyone for replying, and sincerely,
Joshua Choi
[Postscript trimmed.]
Hugh