Forum: JRuby Implementing a Java Interface in JRuby Works Without Include!

Posted by Keith B. (keith_b)
on 2012-08-18 02:19
(Received via mailing list)
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
Posted by Charles Nutter (headius)
on 2012-08-18 02:30
(Received via mailing list)
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
Posted by SAYDUL K. (saydul_k)
on 2012-08-18 20:42
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
Posted by Rohit Namjoshi (Guest)
on 2012-08-18 21:00
(Received via mailing list)
Start with the RailsInstaller - http://railsinstaller.org/. Note that it
installs MRI, not JRuby. You will have to install JRuby from
http://jruby.org/
Posted by SAYDUL K. (saydul_k)
on 2012-08-18 21:04
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
Posted by Keith B. (keith_b)
on 2012-08-18 21:35
(Received via mailing list)
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
Posted by Charles Nutter (headius)
on 2012-08-18 22:46
(Received via mailing list)
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)
Posted by Keith B. (keith_b)
on 2012-08-18 23:40
(Received via mailing list)
Thanks for the clarification, Charlie.

- Keith
Posted by Martin Gross (Guest)
on 2012-08-20 12:40
(Received via mailing list)
Posted by Manuel Ramos (Guest)
on 2012-08-20 14:43
(Received via mailing list)
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." <lists@ruby-forum.com> escribi:
Posted by Manuel Ramos (Guest)
on 2012-08-20 15:45
(Received via mailing list)
Like this http://bitnami.org/stack/rubystack
El 20/08/2012 14:43, "Manuel Ramos" <manuelramoscaro@gmail.com> escribi:
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.