We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpProcessing Implementations › Accessing Java Constants in ruby-processing
Page Index Toggle Pages: 1
Accessing Java Constants in ruby-processing (Read 1297 times)
Accessing Java Constants in ruby-processing
May 19th, 2009, 7:15pm
 
I am trying to access a constant in a java class of the form class.CONSTANT from ruby-processing, but am getting an error:

undefined method 'ON_PRESS' for Java::Procontroll::ControllIO:Class (NoMethodError)

My code:

ON_PRESS = ControllIO.ON_PRESS

I can access the methods of ControllIO without any problems.

Do I need to do something special to get at class constants?
Re: Accessing Java Constants in ruby-processing
Reply #1 - May 20th, 2009, 5:24am
 
Nothing special, you just need to use Ruby syntax for accessing it. In Java, you can access any "member" of an object, be it a method or another object, by saying "object.member". In Ruby, using the dot means a method call, which is why it's complaining about the undefined method. Do this instead:

ControllIO::ON_PRESS

That should make the error make more sense, you can see how

Java::Procontroll::ControllIO

Is a really a class nested inside of two modules.

Good luck with the project.
Page Index Toggle Pages: 1