(NameError) uninitialized constant

Hi,

I am a newbie to JRuby I have issue related to (NameError) uninitialized
constant. it happens when i try to access a ruby class which is at level
module1::module2::class

If i initiate with .new i.e like this module1::module2::class.new i get
error staging as follows
Caused by: org.jruby.exceptions.RaiseException: (NameError)
uninitialized constant module1::module2
at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:2686)

Want to know why this error is coming

Hi there,

this is difficult to say from here. We need sample code to see why it
fails. This is just guess work/a general explanation now:

At first note that modules and classes in ruby have to start with
capital letters.

and for your definition to work you gotta do:

Module1
Module2
MyClass
end
end
end

Module1::Module2::MyClass.new

Cheers,
Tobi

at first glance that just sounds like you have not required the file in
question i.e. require or require_relative but you dont provide enough
context

Charles

Tobias P. wrote in post #1131618:

Hi there,

this is difficult to say from here. We need sample code to see why it
fails. This is just guess work/a general explanation now:

At first note that modules and classes in ruby have to start with
capital letters.

and for your definition to work you gotta do:

Module1
Module2
MyClass
end
end
end

Module1::Module2::MyClass.new

Cheers,
Tobi

Hi,
thanks for the quick response ya the name of modules and classes start
with capital letters.

here’s the scenario
First part is i have a class which is locate at
Module1
Module2
Module3
MyClass
end
def method_test
end
end
end
end

I am calling this method from my java code using java_signature the
method_test calls another method which is at the following location

Module1
Module2
MyClass
def method_to_call
end
end
end
end
when calling from java code it gives error as
Caused by: org.jruby.exceptions.RaiseException: (NameError)
uninitialized constant Module1::Module2::Class

Charles M. wrote in post #1131619:

at first glance that just sounds like you have not required the file in
question i.e. require or require_relative but you dont provide enough
context

Charles

Hi,
thanks Charles for the quick response ya the name of modules and
classes start
with capital letters.

here’s the scenario
First part is i have a class which is locate at
Module1
Module2
Module3
MyClass
end
def method_test
end
end
end
end

I am calling this method from my java code using java_signature the
method_test calls another method which is at the following location

Module1
Module2
MyClass
def method_to_call
end
end
end
end
when calling from java code it gives error as
Caused by: org.jruby.exceptions.RaiseException: (NameError)
uninitialized constant Module1::Module2::Class

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs