[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

question about method call

Li Chen

10/25/2008 9:40:00 PM

Hi all,

I copy a working script from the website. I wonder if method "create"
defined in this class is ever called?


Thanks,

Li

#########script##############
require 'fox16'

include Fox

class HelloWindow < FXMainWindow
def initialize(app)
super(app, "Hello, World!", :width => 200, :height => 100)
end

def create
super
show(PLACEMENT_SCREEN)
end
end

app = FXApp.new
HelloWindow.new(app)
app.create
app.run
--
Posted via http://www.ruby-....

6 Answers

Robert Klemme

10/27/2008 1:09:00 PM

0

2008/10/25 Li Chen <chen_li3@yahoo.com>:
> I copy a working script from the website. I wonder if method "create"
> defined in this class is ever called?

And, what did your tests show?

robert

--
remember.guy do |as, often| as.you_can - without end

Li Chen

10/27/2008 1:37:00 PM

0

Robert Klemme wrote:
> 2008/10/25 Li Chen <chen_li3@yahoo.com>:
>> I copy a working script from the website. I wonder if method "create"
>> defined in this class is ever called?
>
> And, what did your tests show?
>
> robert

It is working. But I am confused: why does app, an instance of
FXApp.new, receive a message defined by class by HelloWindow (or
FXMainWindow) and response it?

Li




--
Posted via http://www.ruby-....

Robert Klemme

10/27/2008 3:47:00 PM

0

2008/10/27 Li Chen <chen_li3@yahoo.com>:
> Robert Klemme wrote:
>> 2008/10/25 Li Chen <chen_li3@yahoo.com>:
>>> I copy a working script from the website. I wonder if method "create"
>>> defined in this class is ever called?
>>
>> And, what did your tests show?
>
> It is working. But I am confused: why does app, an instance of
> FXApp.new,

Read your code again.

> receive a message defined by class by HelloWindow (or
> FXMainWindow) and response it?

You probably need more coffee - or more sleep. :-)

robert

--
remember.guy do |as, often| as.you_can - without end

Li Chen

10/27/2008 5:32:00 PM

0

Robert Klemme wrote:
> Read your code again.
>
>> receive a message defined by class by HelloWindow (or
>> FXMainWindow) and response it?
>
> You probably need more coffee - or more sleep. :-)
>
> robert


Reading from the codes it looks app receive a message from
FXApp.new, which I have no problem to understand that. But if I remove
"create" defined by class HelloWindow(or FXMainWindow) the script
won't work. This is why I am confused.

Li

--
Posted via http://www.ruby-....

Robert Klemme

10/27/2008 5:55:00 PM

0

On 27.10.2008 18:32, Li Chen wrote:
> Robert Klemme wrote:
>> Read your code again.
>>
>>> receive a message defined by class by HelloWindow (or
>>> FXMainWindow) and response it?
>> You probably need more coffee - or more sleep. :-)
>
>
> Reading from the codes it looks app receive a message from
> FXApp.new, which I have no problem to understand that. But if I remove
> "create" defined by class HelloWindow(or FXMainWindow) the script
> won't work. This is why I am confused.

You are right: I am the one who needs more coffee or sleep. :-} I do
not know Fox but I would guess that the FXMainWindow#initialize
registers with FXApp instance and that in turn sends messages it does
not understand to the main window instance. Not difficult to do:

irb(main):001:0> class App
irb(main):002:1> def register(obj)
irb(main):003:2> @delegat = obj
irb(main):004:2> end
irb(main):005:1> def method_missing(*a,&b)
irb(main):006:2> @delegat ? @delegat.send(*a,&b) : super
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> class Win
irb(main):010:1> def initialize(app) app.register(self) end
irb(main):011:1> def boo() puts "boo!" end
irb(main):012:1> end
=> nil
irb(main):013:0> a = App.new
=> #<App:0x7ff64ddc>
irb(main):014:0> w = Win.new a
=> #<Win:0x7ff62438>
irb(main):015:0> a.boo
boo!
=> nil
irb(main):016:0>

Cheers

robert

Li Chen

10/30/2008 4:41:00 PM

0

Hi Robert,

I post my question at fxruby-users@rubyforge.org. Based on the feedback
and what I understand I explain it as follows:

I add some lines to find out 1) object and its corresponding class
2) class and its corresponding superclass(up to final superclass).

Here are what I find:
app object is created by class FXApp and its parent class is FXObject.
hello object is created by class HelloWindow and its parent class is
FXMainWindow.
The final parent for class HelloWindow is FXObject(by repeating calling
method superclass 6-7 times. I call all the parents in this chain as one
of parent chain). And class FXApp never appears in the chain parernt.

Here is my conclusion:
1) the relationship between class FXApp and HelloWindow/FXMainWindow is
horizontal or brother/sister. Their final parent is FXObject(whose final
parent should be Object.) The point here is that in line
app.create(),app objcet REALLY receives #create() defined by its
corresponding class FXApp but not by #create() defined by class
HelloWindow/FXMainWindow. There is no inherence issues between class
FXApp and class HelloWindow/FXMainWindow.

2) But what really happens after app.create() is excuted: it causes
#create() defined by each widget to be called(HelloWindow widget in this
case). This is why class HelloWindow/FXMainWindow has to define
#create() in its class. This might be called window hierarchy but it is
NOT class inherence in Ruby. If I understand correctly it looks like it
is a design strategy for FxRuby: client object and server resource...
And this is what Lyle mentions how Rxruby works on page 90 in chapter 7.


Li



if __FILE__ == $0

FXApp.new do |app|

puts "app belongs to class: #{app.class}"

puts "FXApp has superclasss: #{FXApp.superclass}"

puts

hello=HelloWindow.new(app)

puts "hello belongs to class: #{hello.class}"

puts "HelloWindow has superclasss: #{HelloWindow.superclass}"

app.create

app.run

end

end
--
Posted via http://www.ruby-....