The primitives and arrays especially are
handled in a way that isn??™t natural for a Java programmer, so it??™s important to get these facts
down.
One of the nicer things you can do when interfacing Java and Ruby is to implement Java
interfaces, extend Java classes from Ruby, and then send that code back to Java. For example,
you could implement an OutputStream in a few lines of Ruby code, send it right back into some
FilterOutputStream or whatnot, and it will just work.
JRuby also adds several handy new ways of working with Java collections and Java arrays
by adding many new methods to them. Because of this, some of the more useful things you
can do are to call map on a SortedMap, for example. The possibilities are endless, and useful.
There??™s also another side to the Java integration in JRuby. Sometimes you want to use
Ruby from Java. I??™ll describe three different techniques for how to do this: two that are recommended,
and one that is not so recommended. That part of the chapter will be of most interest
to you if you want to create a Java application that uses Ruby as an extension language, or to
provide macro/plug-in capabilities. It could also be interesting if you want to use Ruby as a
scripting language for web pages instead of Java Server Pages (JSP) or Velocity.
The final part will discuss some gotchas. Because the Java integration in JRuby is on the
boundary between two different kinds of systems, it also contains most of the things that can
go wrong if you don??™t know all the tricks and interesting things that can happen.
Pages:
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182