On Wed, 08 Feb 2006, Damian Steer defenestrated me:
> Hi all,
> 
> I've been playing with jruby for a while now, but there's one thing
> that's stopped me using it more.
> 
> I'd like to wrap (a particular) java library to make it more ruby-ish
> (-esque?), e.g. make things enumerable etc. However this is impractical
> currently since the library is interface oriented, with factories etc.
> Adding methods to the underlying implementation classes is a bad idea,
> of course, and fragile.
> 
> So the request: can this be made to work?
> 
> [[
> require "java"
> include_class "java.util.List"
> include_class "java.util.ArrayList"
> 
> class List
>       def worked
>               puts "WORKED"
>       end
> end
> 
> foo = ArrayList.new
> foo.worked
> ]]
> 
> Thanks (and thanks for jruby generally)

  Yeah this seems to be a bug to me and I will enter it as such.  I think
this fits into the general Ruby way of looking at things (the class 
definition should always be open and inherited classes should still see
the changes).  To fix this we need to make loaded Java classes in turn
load their inherited classes/interfaces as proxies (right now we just
wrap the class as a single proxy and ask java if we can invoke methods on 
it).

  I do have a work-around and I just realized our workaround has some
undesired behavior in it:

require "java"

JavaUtilities.extend_proxy('java.util.List') {
  def worked
    puts "WORKED"
  end
}

include_class "java.util.ArrayList"

foo = ArrayList.new
foo.worked

  The undesired behavior is that we have to extend_proxy before we load the 
java class.  One other caveat is that this syntax for extend_proxy is in 
trunk development and not in 0.8.2 (there is an older syntax for this, but 
we are killing it in favor of the above one -- this used to be an internal 
function that we are making external).

-Tom

-- 
+ http://www.tc.umn.edu/~enebo +---- mailto:[EMAIL PROTECTED] ----+
| Thomas E Enebo, Protagonist  | "Luck favors the prepared    |
|                              |  mind." -Louis Pasteur       |


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Jruby-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to