开发者

very noob question about ruby inheritance, ruby object inside FXRuby

开发者 https://www.devze.com 2023-03-28 03:21 出处:网络
first sorry for my poor english...I\'ve a doubt..I\'m reading the FXRuby for the pragmatic programmer..and I saw this code

first sorry for my poor english...I've a doubt..I'm reading the FXRuby for the pragmatic programmer..and I saw this code

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

It's a very basic example...actually It's he first example..but I'm so noob than I don't understand it:

app is a FXAPP object.. now I create a HelloW开发者_如何学Goindow object and pass my FXApp object named "app"

so far so good

but now...in the book write app.create I'm calling the "create" method inside FXApp class...or not?..

why when I call app.create..ruby call the create method inside HelloWindow?..app is a very different object than HelloWindow class and I could can call an anscestor method (like when I use super) but not at the inverse way...

why they don't call it something like this

helloobject=HelloWindow.new(app)
helloobject.create

this way I calling the create method inside HelloWindows class..and it is descendent from FXMainWindows

I hope than you can understand (sorry for my bad english) and can help me

thanks so much


I don't know anything about FXRuby, but I answer your questions about the Ruby side of things.

When Ruby executes app.create, it will call the create method inside the FXApp class because app's type is FXApp (assuming that there is no create method defined for the singleton class of app).

When you call app.create, there is probably some code in the FXApp class to calls create on all of the windows in the app, so that's how your window's create function gets called. If you want to really find out how your window's create function is being called, try adding raise "hello" to it and see if you get a backtrace of the exception.

I don't really know the answer to your last question because it has to do with the design of the FXRuby library. But conceptually it seems like calling app.create and window.create are very different things. If you want to run the app, you should create it first. Simply creating one window isn't good enough.

0

精彩评论

暂无评论...
验证码 换一张
取 消