From: Benoit Molenda on
Hi,

I have some trouble using module. I'm working on a rails project, but I
think it's concerning Ruby in general.

I get this kind of error 'Module is not missing constant Klass!'

I have folders looking like this :
x/y/klass.rb.

In klass my code is looking something like this :
module x
module y
class klass
end
end
end

In another file :
module x
class Anotherklass
#some method
end
end

When I use once in my methode y::klass everything works fine.
But if I use it twice, the seconde line raise the error : "x is not
missing constant klass".

I tried to load manually the file with require call but it doesn't
change anything.
It's like after the first call, ruby know that Klass is nested into y
but when I use only Klass, ruby raise that he doesn't know Klass ...

I really dunno what to do to solve this. I'm looking arround require and
include.

Thanks for reading
--
Posted via http://www.ruby-forum.com/.

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Tue, Mar 30, 2010 at 1:47 AM, Benoit Molenda <devanth(a)gmail.com> wrote:

> Hi,
>
> I have some trouble using module. I'm working on a rails project, but I
> think it's concerning Ruby in general.
>
> I get this kind of error 'Module is not missing constant Klass!'
>
> I have folders looking like this :
> x/y/klass.rb.
>
> In klass my code is looking something like this :
> module x
> module y
> class klass
> end
> end
> end
>
> In another file :
> module x
> class Anotherklass
> #some method
> end
> end
>
> When I use once in my methode y::klass everything works fine.
> But if I use it twice, the seconde line raise the error : "x is not
> missing constant klass".
>
> I tried to load manually the file with require call but it doesn't
> change anything.
> It's like after the first call, ruby know that Klass is nested into y
> but when I use only Klass, ruby raise that he doesn't know Klass ...
>
> I really dunno what to do to solve this. I'm looking arround require and
> include.
>
> Thanks for reading
> --
> Posted via http://www.ruby-forum.com/.
>
>
Classes and modules are constants, so their names need to begin with
Uppercase Letters.

From: Benoit Molenda on
Josh Cheek wrote:
> Classes and modules are constants, so their names need to begin with
> Uppercase Letters.

Yes, sorry for my exemple, my real code follow of course the naming
style.
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Benoit Molenda wrote:
> Josh Cheek wrote:
>> Classes and modules are constants, so their names need to begin with
>> Uppercase Letters.
>
> Yes, sorry for my exemple, my real code follow of course the naming
> style.

So show a real piece of Ruby code which replicates the problem -
something we can paste into a file and run for ourselves.

Often, in boiling down a problem into a simple test case like that,
you'll discover what the problem is. And if you don't, you will have
made it much easier for others to determine what the problem is.
--
Posted via http://www.ruby-forum.com/.

From: Benoit Molenda on
Brian Candler wrote:
> Benoit Molenda wrote:
>> Josh Cheek wrote:
>>> Classes and modules are constants, so their names need to begin with
>>> Uppercase Letters.
>>
>> Yes, sorry for my exemple, my real code follow of course the naming
>> style.
>
> So show a real piece of Ruby code which replicates the problem -
> something we can paste into a file and run for ourselves.
>
> Often, in boiling down a problem into a simple test case like that,
> you'll discover what the problem is. And if you don't, you will have
> made it much easier for others to determine what the problem is.
Sure.

I create a test app with this code.
In app/controller/local/class_generator_controller.rb :

class Local::VerticalGeneratorController < ApplicationController
def index
@models = VerticalBuilder::Vertical.list
@models = VerticalBuilder::Vertical.list #second call raise an
exception
end
end

In lib/local/vertical_builder/vertical.rb :
module Local
module VerticalBuilder
class Vertical
def self.list
[]
end
end
end
end

I get the same error when I call
http://localhost:3000/local/vertical_generator :
Local is not missing constant VerticalBuilder!
It seams that Ruby try to load each time the Constant instead of look
into already loaded...
--
Posted via http://www.ruby-forum.com/.