title: JRuby: Documentation of mappings/conversions between Java and Ruby types/classes?
body: <p>I am writing a Java wrapper library around a ruby gem so I am embedding ruby within Java and not the other way around. I seem to be in the vast minority!</p>
  
  <p>If I have a ruby method that returns a <code>Time</code> object then I can very easily convert it into a <code>java.util.Date</code> object on the Java side like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>public Date getStartTime() {
      IRubyObject result = RuntimeHelpers.invoke(runtime.getCurrentContext(),
          this, "start_time");
      return (Date) result.toJava(Date.class);
  }
  </code></pre>
  
  <p>But I think I got lucky working this out by trial and error and not all like-seeming types can be converted in this way. I have another ruby method that returns a <code>URI</code> object (it could be a <code>URI::HTTP</code> or a <code>URI::HTTPS</code> in fact) but trying the obvious (given the above) conversion to a <code>java.net.URI</code> doesn't work (I also tried it with <code>java.net.URL</code>):</p>
  
  <pre class="lang-java prettyprint-override"><code>public URI getUri() {
      IRubyObject result = RuntimeHelpers.invoke(runtime.getCurrentContext(),
          this, "uri");
      return (URI) result.toJava(URI.class);
  }
  </code></pre>
  
  <p>This code compiles, but fails at run time:</p>
  
  <pre><code>Exception in thread "main" org.jruby.exceptions.RaiseException: (TypeError) cannot
  convert instance of class org.jruby.RubyObject to class java.net.URI
  </code></pre>
  
  <p>I realise that in ruby a <code>URI</code> is actually a module and <code>URI::HTTPS</code>, etc are the classes, so I'm not entirely surprised that the above didn't work. But there's clearly a bit of internal "magic" being done for the <code>Time</code>/<code>Date</code> example so I was wondering if there were similar conversions provided for other types, which types and where they are documented.</p>
  
  <p>Any pointers much appreciated.</p>