[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Forward references?

seebs

5/26/2007 11:41:00 AM

In message <3a94cf510705260432r5157b607wae9cd16ce61aa6a7@mail.gmail.com>, "Fran
cis Cianfrocca" writes:
>The fact that "Foo::Bar" is undefined in Foo#initialize doesn't matter to
>Ruby's parser. The whole notion of "forward references" is really more at
>home in languages that build symbol-tables at compile time. Ruby just deals
>with the names themselves.

class A::B
end
class A
end
--> t.rb:1: uninitialized constant A (NameError)

So I can't just do them in ANY order.

>Two possible reasons: you want to segregate them textually to make your code
>easier to read, or you want to support multiple definitions of Bar, to be
>determined at runtime. In either case, you can place the require statements
>where it makes the most sense for the user of Foo. You can defend yourself
>against Bar being required ahead of Foo by coding it like this:

The rationale was essentially to segregate them textually. I like
having moderately self-contained things in separate files, even if they
have some necessary cohesion.

Hmm.

I had the brief notion of writing
module A
require 'b.rb'
end
and ending up with a class named A::B, but B ends up outside
of A anyway. So much for my clever idea. :)

-s