Implementing a Java Interface in JRuby Works Without Include!

Hi, there. I learned about using ‘include’ to implement a Java
interface in JRuby. However, I can’t determine what effect it really
has. I tried creating a Runnable implementation without using the
include, and, to my surprise, it ran without errors. Why?

The code is at https://gist.github.com/3383582.

Thanks,
Keith

When an argument to a Java method takes an interface, you can pass
any object. We will create a hidden implementation of the interface
behind the scenes and pass that; it will proxy all calls to your
object.

For example:

system ~/projects/jruby $ javap Runnables
Compiled from “runnables.mirah”
public class Runnables {
public static java.lang.Runnable run(java.lang.Runnable,
java.lang.Runnable, java.lang.Runnable);
public Runnables();
}

system ~/projects/jruby $ jruby -rjava -e “Java::Runnables.run(->{puts
‘hi’}, ->{puts ‘from’}, ->{puts ‘JRuby’})”
hi
from
JRuby

Easy-peasy!

  • Charlie

I want to learn ruby on rails using my laptop which run windows XP.
please any one help me which software’s i must download for XP. specify
the s/w name with version and any step by step guide line is on the net
that help me to install, working/programming with ruby on rails and can
able to develop any web applications in future.

Regards

Start with the RailsInstaller - http://railsinstaller.org/. Note that it
installs MRI, not JRuby. You will have to install JRuby from
http://jruby.org/

Charlie -

Thanks for responding.

So are you saying that using ‘include’ for an interface implementation
is not necessary? Does it provide any functionality at all? When would
one use it?

Thanks,
Keith

Using include will perform a bit better because we can immediately see
the
interfaces the object supports and we also can make the Java object
representing the Ruby object actually implement those interfaces
rather
than generating/instantiating a separate object attached to the Ruby
object.

I believe dispatch from Java through the interface is faster using a
class

  • include than the “magic” form too.
  • Charlie (mobile)

Thanks for the clarification, Charlie.

  • Keith

You could try http://railsinstaller.org/

I want to learn ruby on rails using my laptop which run windows XP.
please any one help me which software’s i must download for XP. specify
the s/w name with version and any step by step guide line is on the net
that help me to install, working/programming with ruby on rails and can
able to develop any web applications in future.

Regards

Like this http://bitnami.org/stack/rubystack
El 20/08/2012 14:43, “Manuel R.” [email protected] escribi:

The easy way may be a rack vm that contains a full installation of rails
ready to work
El 18/08/2012 21:05, “SAYDUL K.” [email protected] escribi:

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