# Question about method call

**URL:** <https://www.ruby-forum.com/t/question-about-method-call/151798>\
**Category:** Ruby\
**Created:** [October 25, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798 "2008-10-25T23:40:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 25, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/1 "2008-10-25T23:40:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 27, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/2 "2008-10-27T14:10:13Z")

</div>

2008/10/25 Li Chen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 27, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/3 "2008-10-27T14:37:53Z")

</div>

Robert K. wrote:

> 2008/10/25 Li Chen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > 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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 27, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/4 "2008-10-27T16:48:34Z")

</div>

2008/10/27 Li Chen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Robert K. wrote:
> 
> > 2008/10/25 Li Chen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> > 
> > > 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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 27, 2008, 6:32pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/5 "2008-10-27T18:32:46Z")

</div>

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. 🙂
> 
> 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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 27, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/6 "2008-10-27T19:00:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 30, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/question-about-method-call/151798/7 "2008-10-30T17:41:45Z")

</div>

Hi Robert,

I post my question at removed\_email\_address@domain.invalid. 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
