[rjb-users] Mapping Java packages onto Ruby modules
rjb-users at rubyforge.org
rjb-users at rubyforge.org
Wed Oct 25 21:22:29 EDT 2006
--- arton <arton at e07.itscom.net> wrote:
> Hi Rich
> I've just read your article, and found it's smart.
> My first thougt for design decition of Rjb::import
> is just Java's import
> In Java codes, people just write as
> import javax.imageio.ImageIO;
> But in Ruby, I changed the meaning of 'import' from
> Java's original
> statement to 'import Java class into Ruby class'.
> It's simple and intuitive for writing RubyClass =
> And I like the design that doesn't require just one
> solution for manys.
Yes, I do like the way RJB does it currently. It's an
approach that can work in just about any situation.
And it's perfect for building higher-level interfaces.
> Because I don't like import Java class into a
> constant for example
> ImageIO = Rjb::import('javax....
Yes, I started off doing that, but it's asking for
trouble. For example:
String = Rjb::import('java.util.String')
> But also I don't like import it into instance
> variable as
> @imageIO = Rjb::import('....
> Also I don't like import it into Javanizied (camel
> case) name as
> imageIo = Rjb::import(...
> I just like Ruby style name
> image_io = Rjb::import('....
> So, with my approach, people can choose imported
> class name as they like,
> or as their coding style.
> By the other hand, your thought for 'resulting
> duplications of Java class
> names and variable names doesn't smell especially
> good,' is not so wrong
> and I accept it has some correctness. (But 'nor does
> it scale well' is
> not right, as my English kowledge. 'scale' is the
> word for the
> scalability, Rjb never import the calss twice, so
> a = Rjb::import('java.A')
> anothera = Rjb::import('java.A')
> a == anothera ... true (because they point same
> Rjb's imported class instance,
"Scale" might not be the best word. I guess what I
meant is that it's repetitive for the programmer.
> Because the imported real class is a singleton, and
> I think it's better
> to hide it under the water)
> BTW, your design for mapping to Ruby's module is
> quite interresting for
> And I introduce the another aproach for Rjb::import
> by Andrew (cc for
> this mail) to you. He programmed Rjb wrapper class
> for including Ruby
> class to easy access the java methods.
This looks very nice. It looks like the code adds the
ability to use ruby-like method names on the Java
objects ('element_at' instead of 'elementAt'. I
noticed JRuby does this and I really like it. I'll
check out the code in more detail.
> (see the attachment)
> I like both approach (and my own approach too) for
> the bridging.
> Then would I include your jrequire code (java.rb)
> into the Rjb package ?
No need to do that just yet - I'm still experimenting
with the best way to do this. One of the things I'm
thinking about how to get to where I can do this:
require 'java/util/' # Builds all of the
# Java::Util classes at once.
# Also, no jrequire.
# now there's no need to require each
# class separately
v = Java::Util::Vector.new
al = Java::Util::ArrayList.new
I'm new to Ruby, but from what I can tell, this is
essentially the way pure Ruby modules would be defined
and used. Performance might be a problem, though, with
creating all classes in a package. What do you think?
Also, is there a way for RJB to get all of the class
names in a Java package?
> Or would you please join the Rjb project for adding
> your approach ? If
> you would to, I add you for the developer into Rjb
> project on RubyForge,
> so you can add the codes into the subersion
> repositry on RubyForge.
Sure. I'm not confident enough in my knowledge of how
RJB works to do much coding, but I might start by
trying my hand at writing some doucmentation.
I hope you don't mind, but I've also forwarded this
email to the rjb-users list. Maybe we can continue the
> On Tue, 24 Oct 2006 07:50:50 -0700 (PDT)
> richard apodaca <rich_apodaca at yahoo.com>ï¿½ï¿½ï¿½ï¿½
> > Hi Arton,
> > I've just written an article that talks about
> > Java packages onto Ruby modules:
> > Do you have any plans to include functionality
> > this in future releases of RJB? I'm not sure the
> > approach I've otlined is the best one, but
> > like it could be very useful.
> > cheers,
> > Rich
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the rjb-users