Question about method call

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

2008/10/25 Li Chen [email protected]:

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

Robert K. wrote:

2008/10/25 Li Chen [email protected]:

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

2008/10/27 Li Chen [email protected]:

Robert K. wrote:

2008/10/25 Li Chen [email protected]:

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. :slight_smile:

robert

Robert K. 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. :slight_smile:

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

On 27.10.2008 18:32, Li Chen wrote:

“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

Hi Robert,

I post my question at [email protected]. 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