0
I-| ano| s—on JRuby: 
Making Your Job Easy

Thomas Enebo,  Charles Nutter
Engine Yard
Goal

- Get an idea of how . JRuby can help you in day—to—day
development
Introduction

3 JRuby Guys
at 4 Years as our “day job”
a We still eat and breath Java but drink beer

a 15 years and still...
ll(’l)(), 

I.  no-o. ..u. o
u
, ... o.. v~

; 
-c

0-
Clizirlc-s () Null: -r. 

Nick Sleger. 

'I‘hnm: is E

Ola Bml.  an...
JRuby @ lO_OOO

E: 

E3

E3

Implementation of Ruby runtime that runs on a JVM
http: //www. jruby. org/ 

OpenSouroe (CPL,...
Ruby Quick Tour

- The relative feel between Java and Ruby
Circle Shape { Circle < Shape
int radius;  initialize(radiuS)
@radius =  radius
Circle(int radius) {
. radius =  radius; 
...
Single Inheritance

/  Same Thing 
Circle(: ::: ::: )Shape { Circ1e(: )Shape

int radius;  initialize(radius)
@radius =  r...
Constructor

Circle Shape { Circle < Shane
int radius;  initialize(radius)
@radius =  radius
Circle(int radius) {
. radius...
No Type Declarations

Circle Shape { Circle < Shape
int radius;  initialize(radius)
@radius =  radius
Circle(int radius) {...
Dynamic Typing

a Ruby is Dynamically Typed
as Why we see no Type decls on variables
a Runtime type—checking (like Java ca...
Instance Variables

‘@’ = = ‘this. ’ and is mandotory

Circle Shape { Circle < Shape
int radius;  initialize(radius)
@radi...
No Returns

Last Expression is always return value

Circle Shape { Circle < Shape
int radius;  initialize(radius)
@radius ...
.new is just a class method! 

Circle Shape { Circle < Shape
int radius;  initialize(radius)
@radius =  radius
Circle(int ...
.. .,. 

o-coco.  oooooooo octane 2

. uv-coo co ooooooo.  oooouooo to

.  -. ooouoo ooouccoo

. u.. ooo ooooocoo couooooo...
JRuby Features

vs Call into Ruby from Java
a Java 6 Scripting
E Internal “Red Bridge” API
rs Access Java classes from Rub...
Access Ruby from Java

Scriptingcontainer container =  new ScriptingContainer(); 

container. put(”$revisions",  new Revis...
Use Case:  Scripting Java

a One—off scripts are easy as opening an editor
a Not everything must be an iDE project
at Easy...
Demo:  Java from Ruby
Demo:  Scripting Java
Ant + Rake %  l'j‘gj%; vti. 

 

- Ant is 800 pound Gorilla of Java
- Declarative and a little Dumb but Dependable

- Used...
Ant + Rake

- Rake is Orangutang of Ruby
- Like Make or Ant

 

- . ... but with Ruby + Imperative Goodness
Ant + Rake

I Call Rake From Ant

I Call tasks

I Rake tasks as Ant target dependencies
I Call Ant From Rake

I Ditto! 
I ...
Rake Calling Ant Tasks

require 'rake'
require 'ant'
task : init do

: dir = > 'build'
end

task : compile = > : init do
:...
Rake Calling Ant

task : call_ant do
'—f my_build. xml its_in_ant'
end

task : ant_import do
# you could also do this outs...
.
. 
.
-O
. 
o"
5:f§5§35
1.0.0.0.
:4~'r
r J -D L
', .;§: $'
;5a; =
‘. o‘: ‘,¥‘
£23;
1,
5”’
4"
V
O

l'>

= "UTF—8"? >
= "de...
Ant Calling Rake Tasks

<? xml version= ”l. O" encoding= ”UTF—8"? >

<project name= ”foobar" default= "top—level" basedir=...
Ruby on Rails

at Still setting the bar for web frameworks
a RESTfu|  services
a HTML5
R JQuery
3 Rails 3

R Cleanups,  im...
JRuby on Rails

I Deploy Rails on any Java server

I WARfile—based

I “| ightweight” command—| ine server

I Use all the J...
Demo:  Rails Simple
Demo:  Rails + Java
Demo:  Rails Deployment
JRuby Meetupl

I Tuesday,  September 21  I t   1

5:30 pm — 7:00 pm Networking,  beer and food
7:00 pm — 8:00 pm Lightning...
Conclusion

I Ruby is easy to learn for Java programmers

I Easy to mix Ruby+Java

I Useful Productivity Frameworks and Li...
Cther Talks

I Script Bowl
I (Going on right now)

I Fast Web Applications Development with Ruby on Rails
on Oracle

I Hot...
Thank You

I twitter:  headius,  tom_enebo

I website:  http: //www. iruby. org/ 
I blogs:  blog. headius. com,  http: //b...
Demo:  3D Java from Ruby
Upcoming SlideShare
Loading in...5
×

JavaOne 2010 - JRuby

1,260

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,260
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide





































  • Transcript of "JavaOne 2010 - JRuby"

    1. 1. I-| ano| s—on JRuby: Making Your Job Easy Thomas Enebo, Charles Nutter Engine Yard
    2. 2. Goal - Get an idea of how . JRuby can help you in day—to—day development
    3. 3. Introduction 3 JRuby Guys at 4 Years as our “day job” a We still eat and breath Java but drink beer a 15 years and still here
    4. 4. ll(’l)(), I. no-o. ..u. o u , ... o.. v~ ; -c 0- Clizirlc-s () Null: -r. Nick Sleger. 'I‘hnm: is E Ola Bml. and Ian Dec-s l*. ‘rlIlI-rl bl]-klfflllflllll (‘urn-r Iaeiu :1. 0 o 5 -0.‘. A o 5' 0 .0 494* u m . R W J M. .. ma S B U '0 1'. » din‘ 3'3’? »". .¢2¢‘ oovuc #5 coat iovcustuln
    5. 5. JRuby @ lO_OOO E: E3 E3 Implementation of Ruby runtime that runs on a JVM http: //www. jruby. org/ OpenSouroe (CPL, LGPL, GPL) Requires Java 5+ Many Features
    6. 6. Ruby Quick Tour - The relative feel between Java and Ruby
    7. 7. Circle Shape { Circle < Shape int radius; initialize(radiuS) @radius = radius Circle(int radius) { . radius = radius; attr_reader zradius int getRadius() { radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String[] a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area);
    8. 8. Single Inheritance / Same Thing Circle(: ::: ::: )Shape { Circ1e(: )Shape int radius; initialize(radius) @radius = radius Circle(int radius) { . radius = radius; attr_reader zradius int getRadius() { radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String[] a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area);
    9. 9. Constructor Circle Shape { Circle < Shane int radius; initialize(radius) @radius = radius Circle(int radius) { . radius = radius; attr_reader zradius int getRadius() radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String[] a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area);
    10. 10. No Type Declarations Circle Shape { Circle < Shape int radius; initialize(radius) @radius = radius Circle(int radius) { . radius = radius; attr_reader zradius int getRadius() { radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String| | a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area);
    11. 11. Dynamic Typing a Ruby is Dynamically Typed as Why we see no Type decls on variables a Runtime type—checking (like Java casts) a ‘‘If it waddles like a duck and quacks like a duck. ..”
    12. 12. Instance Variables ‘@’ = = ‘this. ’ and is mandotory Circle Shape { Circle < Shape int radius; initialize(radius) @radius = radius Circle(int radius) { . radius = radius; } attr_reader zradius int getRadius() { radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String[] a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area);
    13. 13. No Returns Last Expression is always return value Circle Shape { Circle < Shape int radius; initialize(radius) @radius = radius Circle(int radius) { . radius = radius; attr_reader zradius int getRadius() { radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String[] a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area); }
    14. 14. .new is just a class method! Circle Shape { Circle < Shape int radius; initialize(radius) @radius = radius Circle(int radius) { . radius = radius; attr_reader zradius int getRadius() { radius; area Math: :PI*(@radius ** 2) double getArea() { Math. PI * Math. pow(radius,2); void main(String[] a) { g»~< Circle. new(2). area double area= Circle(2). getArea(); System. out. println(area);
    15. 15. .. .,. o-coco. oooooooo octane 2 . uv-coo co ooooooo. oooouooo to . -. ooouoo ooouccoo . u.. ooo ooooocoo couooooo cocoon. coco C 441444441114411414441111114:1 ¢14u¢: q44AmaA 4 arcane ococcov vuovoooooo 000 cont vccuunu. Jf oaooooooo co-coco ooooooo ocaooooaoco . o / o coco coon no oanopavoa 1 _ J%%J$J%%JLJi%f my . .a. ... . . .. ... ... .,. .. 4 I O OOJJOIO . Am? J? o . . o u ntoooot oouuoooo 00000000 000000: 000000 - 0 no 0000000 oononbn ooooooo oooconoc 00 oooonuoc olooooooo oouoooc 0 cocoons ooaoooo uouovov . ... . L. o 0 a o Ioocoooo one-o. .l| I>o ucsnouou ouvooooo Dflflx oonoooo ooooouco 09 ooooooo ooooo-cc OOOIQOO no-ocooovov It! ran: oocuoooo oonooPfiP 00000000 coo-coco an-on-3:15: ooooouo oaflcucoooooo ocooooo ooooooooo qua. 1/n-pvnoi . .. . O coo noooooou -so-noun IIIOIIIO IUIOCUOI n ooouoooo oPoooooooo oooooooo -no-nnooooooooooovvnn nooooooo oooooooo oosuuota so 3 :00 C4 is 3 . ... ... .. .. ... uuw. 00.0000 ooouo oooooon oclloooooo 000000 coco-ov4s uouu a II o ooocoo OIO oooooovJo 0099 of tycoon 1 uooooooooa | io . gets mode ile) io I ya u; . _. aflwtll . M.. _.»_. .. a . ¢. .ota. ...4.. ...1. A oucdaaocooc JP 5 oflffflxflu JJIT J%%flJ3%% ET 1%? , . . le, 0 Joyce: av-ooh oooooo ( on too; noooooo i . open(f t line open(f ile io c ocoactudioooo aoaocuoauflm my_open(file) do firs e d def my_ io = F yield ensure io. close end
    16. 16. JRuby Features vs Call into Ruby from Java a Java 6 Scripting E Internal “Red Bridge” API rs Access Java classes from Ruby Er Call, Decorate, and Define in Ruby
    17. 17. Access Ruby from Java Scriptingcontainer container = new ScriptingContainer(); container. put(”$revisions", new Revisions(args[0], args[1])); List<Diff> f = (List<Diff>) container. runScriptlet("history”); for (GitDiff f) { System. out. println("FILE: " + file. getPath()); System. out. println(file. getPatch());
    18. 18. Use Case: Scripting Java a One—off scripts are easy as opening an editor a Not everything must be an iDE project at Easy to play with technology
    19. 19. Demo: Java from Ruby
    20. 20. Demo: Scripting Java
    21. 21. Ant + Rake % l'j‘gj%; vti. - Ant is 800 pound Gorilla of Java - Declarative and a little Dumb but Dependable - Used Everywhere
    22. 22. Ant + Rake - Rake is Orangutang of Ruby - Like Make or Ant - . ... but with Ruby + Imperative Goodness
    23. 23. Ant + Rake I Call Rake From Ant I Call tasks I Rake tasks as Ant target dependencies I Call Ant From Rake I Ditto! I Mix and Match
    24. 24. Rake Calling Ant Tasks require 'rake' require 'ant' task : init do : dir = > 'build' end task : compile = > : init do : destdir = > 'build' do : location = > 'src' end end task : test = >
    25. 25. Rake Calling Ant task : call_ant do '—f my_build. xml its_in_ant' end task : ant_import do # you could also do this outside end task : compile = > [: ant_import, # Do some compilation end
    26. 26. . . . -O . o" 5:f§5§35 1.0.0.0. :4~'r r J -D L ', .;§: $' ;5a; = ‘. o‘: ‘,¥‘ £23; 1, 5”’ 4" V O l'> = "UTF—8"? > = "defau1t" basedir= " = "org. jruby. ant. Rake"/ > ing default " classname rake n! > = "1.0" encod = "foobar" <description>Bui1ds, tests, and runs the project foobar. ="jar : § <? xm1 version -2 <project name 3 </ description> <target name= "1oad—rake—task"> <taskdef name </ target> <target name= "default" depends= "load—rake—task"> <rake task </ target> </ project>
    27. 27. Ant Calling Rake Tasks <? xml version= ”l. O" encoding= ”UTF—8"? > <project name= ”foobar" default= "top—level" basedir= "."> <description>Builds the project foobar. </description> <target name= ”top—level” depends= ” <target name= ”its_in_ant"> <echo message= "ant: its_in_ant"/ > </ target> </ project>
    28. 28. Ruby on Rails at Still setting the bar for web frameworks a RESTfu| services a HTML5 R JQuery 3 Rails 3 R Cleanups, improvements, features
    29. 29. JRuby on Rails I Deploy Rails on any Java server I WARfile—based I “| ightweight” command—| ine server I Use all the Java libs you have today I Best of both worlds!
    30. 30. Demo: Rails Simple
    31. 31. Demo: Rails + Java
    32. 32. Demo: Rails Deployment
    33. 33. JRuby Meetupl I Tuesday, September 21 I t 1 5:30 pm — 7:00 pm Networking, beer and food 7:00 pm — 8:00 pm Lightning talks I Engine Yard, Inc. 500 Third Street (@ Bryant Street) Suite 510 San Francisco, CA 94107
    34. 34. Conclusion I Ruby is easy to learn for Java programmers I Easy to mix Ruby+Java I Useful Productivity Frameworks and Libraries I Rails, Rake I One more tool for Java programmer’s toolbelt
    35. 35. Cther Talks I Script Bowl I (Going on right now) I Fast Web Applications Development with Ruby on Rails on Oracle I Hotel Nikko, Golden Gate, 2:30 Today I PL/ SOL Unit Testing Can Be Fun! I Hotel Nikko, Bay View, 9:30 Tomorrow
    36. 36. Thank You I twitter: headius, tom_enebo I website: http: //www. iruby. org/ I blogs: blog. headius. com, http: //b| og. enebo. com
    37. 37. Demo: 3D Java from Ruby
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×