Forums FXRuby

 
Generic-user-small Thomas Wiecz... 5 posts

I finished the third chapter and I am right now starting the fourth, but I don’t get one thing. Where does the PhotoView class gets its knowlegde of the app instance(page 33, pdf)?
Here’s the code:

class PhotoView < FXImageFrame

    def initialize(p, photo)
        super(p, nil)
        load_image(photo.path)
    end

    def load_image(path)    
        File.open(path, "rb") do |file|
            # I don't get it why "app" works!
            self.image = FXJPGImage.new(app, file.read)
        end
    end
end

app is only defined in the PictureBook class. How come that it works?

 
Generic-user-small Thomas Wiecz... 5 posts

All right, I get it!
app is an instance variable of the superclass. You could also write self.app instead.

Sorry for the ruckus

 
Lovablelyle_small Lyle Johnson 21 posts

Thomas, you are a fast reader! Glad you figured it out on your own, but I’ll make a note to myself that that could be clearer in the book’s discussion of the code.

 
Generic-user-small Thomas Wiecz... 5 posts

It’s a great book and I like how you go through the iterations.

IMHO it is more readable, when I add self to attributes which belong to the current class. I learned the hard way in Java that it is not much more to write to add this, but it keeps the code clearer for later reviews.

4 posts, 2 voices