SlideShare a Scribd company logo
Ruby for Java Programmers Mike Bowler President, Gargoyle Software Inc.
Why learn another language?
Why Ruby?
Timeline: 1993 to 2000 Created in 1993 by Yukihiro "Matz" Matsumoto Ruby was popular in Japan but unknown everywhere else All documentation was written in Japanese
Timeline: 2000-2004 First English language book published in 2000  A lot of interest in the Agile development community but mostly unknown elsewhere
Timeline: 2004-today The Ruby on Rails framework has pushed ruby into the spotlight This is the “killer app”
What influenced it?
Terminology Early Late Static Dynamic Strong Weak
Defining strong/weak typing Strong typing Objects are of a specific type and will not be converted automatically Java: “4”/2 results in a compile error Weak typing Objects can be converted under the covers at any time Perl: ‘4’/2 => 2 Ruby is strongly typed
Early/late binding Early binding (aka static binding) All method invocations must be defined at compile time Java: foo.getUser() Late binding (aka dynamic binding) The runtime does not check that a given method exists until an attempt to invoke it Smalltalk: foo user. Ruby uses late binding
Similarities Like Java, Ruby... runs on a virtual machine is garbage collected is object oriented (although to different degrees)
Differences Everything is an object Java string = String.valueOf(1); Ruby string = 1.to_s() Primitive Object
Differences Many things that you would expect to be keywords are actually methods throw  new IllegalArgumentException( "oops" ); raise  TypeError.new( "oops" ) Keywords Methods
Differences Some syntax optional unless the result is ambiguous These statements are equivalent puts( "foo" ); puts  "foo" Idiomatic (better) style
Differences Classes are real objects They’re instances of Class Class methods can be overridden
class  ZebraCage < Cage attr_accessor  :capacity @@allCages  = Array. new def  initialize maximumZebraCount @capacity  = maximumZebraCount @@allCages  << self end private def  clean_cage # do some stuff here end end cage = ZebraCage. new   10 puts cage.capacity
Multiline if if  name. nil ? do_something end
Multiline if if  name. nil ? do_something end Notice the question mark
With an else if  name. nil ? do_something else something_else end
Single line if if  name. nil ? do_something end do_something  if  name. nil ?
Both kinds of unless if  name. nil ? do_something end do_something  if  name. nil ? unless  name. nil ? do_something end do_something  unless  name. nil ?
Dangerous methods name =  &quot;   foo   &quot; name.strip name.strip! Returns a new string. Doesn’t modify name. Modifies name  and returns that. Dangerous!
Philosophy Java focuses on building blocks You can build whatever you want with the pieces Ruby focuses on solving problems Things you do frequently should be concise
Initializing arrays List<String> list =  new  ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; );
Same only ruby List<String> list =  new  ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); list = Array.new list <<  'foo' list <<  'bar'
[] List<String> list =  new  ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); list = Array.new list <<  'foo' list <<  'bar' list = [ 'foo' ,  'bar' ]
%w() List<String> list =  new  ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); list = Array.new list <<  'foo' list <<  'bar' list = [ 'foo' ,  'bar' ] list =  %w(foo   bar)
In fairness to java... List<String> list =  new  ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); List<String> list = Arrays.asList( &quot;foo&quot; ,  &quot;bar&quot; ); list = Array.new list <<  'foo' list <<  'bar' list = [ 'foo' ,  'bar' ] list =  %w(foo   bar)
Same idea with hashes Map<String,String> map    = new HashMap<String,String>(); map.put( &quot;foo&quot; ,  &quot;one&quot; ); map.put( &quot;bar&quot; ,  &quot;two&quot; ); map = { 'foo'  =>  'one' ,  'bar'  =>  'two' }
Special case for Hash hash = { :a  =>  5 ,  :b  =>  3 } do_stuff  30 , hash do_stuff  100 ,  :a  =>  5 ,  :b  =>  3
Regular Expressions Pattern pattern = Pattern.compile( &quot;^\\s*(.+)\\s*$&quot; ); Matcher matcher =  pattern .matcher(line); if ( matcher.matches() ) { doSomething(); }
Regular Expressions Pattern pattern = Pattern.compile( &quot;^\\s*(.+)\\s*$&quot; ); Matcher matcher =  pattern .matcher(line); if ( matcher.matches() ) { doSomething(); } do_something  if  line =~  /^\s*(.+)\s*$/
Nil and Null Java’s null Ruby’s nil Absence of an object An instance of NilClass if( a != null ) {...} unless a.nil? {...} null.toString() -> NPE nil.to_s -> “” null.getUser() -> Exception in thread &quot;main&quot; java.lang.NullPointerException nil.get_user ->  NoMethodError: undefined method ‘get_user’ for nil:NilClass
Implications of late binding Method dispatch is quite different Ruby makes a distinction between “messages” that are sent to an object and the “methods” that get dispatched
Message != Method
What if there isn’t a method for the specified message?
method_missing example from ActiveRecord user = Users.find_by_name(name) user = Users.find( :first ,  :conditions  => [  &quot;name = ?&quot; , name])
Creating proxy objects Mock object for testing Proxy object to allow distributed objects across machines Wrapper to record usage of a given object
Implementing a proxy class  Proxy def  method_missing name, *args, &proc puts name,args end end
Implementing a proxy class  Proxy def  method_missing name, *args, &proc puts name,args end end Proxy. new .foo_bar ‘a’ Proxy. new .to_s Dispatches to  method_missing Doesn’t go to  method_missing
Overriding to_s class  Proxy def  method_missing name, *args, &proc puts name,args end def  to_s method_missing :to_s, [] end end
= • === • =~ • __id__ • _send__ • class • clone • dclone display • dup • enum_for • eql? • equal? • extend   freeze frozen? • hash • id • inspect • instance_eval instance_of? instance_variable_defined • instance_variable_get instance_variable_get • instance_variable_set   instance_variable_set • instance_variables • is_a? kind_of? • method • methods • new • nil? • object_id  p rivate_methods • protected_methods • public_methods remove_instance_variable • respond_to? • send singleton_method_added • singleton_method_removed singleton_method_undefined • singleton_methods • taint tainted? • to_a • to_enum • to_s • to_yaml to_yaml_properties • to_yaml_style • type • untaint
Implementing a proxy class  Proxy instance_methods.each do |method| undef_method method unless method =~ /^__/ end def  method_missing name, *args, &proc puts name,args end end Proxy. new .to_s
Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things. — Doug Gwyn
Cultural differences about type Java is very focused on the types of objects Is the object an instance of a specific class? Or does it implement a specific interface? Ruby is focused on the behaviour Does the object respond to a given message?
Types public   void  foo( ArrayList list ) { list.add( &quot;foo&quot; ); } def  foo list list <<  'foo' end What’s the type? What’s the type?
Duck typing def  foo list list <<  'foo' end If list is a String => ‘foo’ If list is an Array => [‘foo’] If list is an IO => string will be written to stream
Duck typing Duck typing implies that an object is interchangeable with any other object that implements the same interface, regardless of whether the objects have a related inheritance hierarchy. -- Wikipedia &quot;If it walks like a duck and quacks like a duck, it must be a duck.&quot; -- Pragmatic Dave Thomas
How does this  change how we think of types? think of types? think of types?
Overflow conditions int  a = Integer. MAX_VALUE ; System. out .println( &quot;  a=&quot; +a); System. out .println( &quot;a+1=&quot; +(a+1)); a=2147483647 a+1= ??
Overflow conditions int  a = Integer. MAX_VALUE ; System. out .println( &quot;  a=&quot; +a); System. out .println( &quot;a+1=&quot; +(a+1)); a=2147483647 a+1=-2147483648 oops
Overflow in ruby? number =  1000 1 .upto( 4 )  do puts  &quot;#{number.class} #{number}&quot; number = number * number end Fixnum 1000 Fixnum 1000000 Bignum 1000000000000 Bignum 1000000000000000000000000
Closures A closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables. The explicit use of closures is associated with functional programming and with languages such as ML and Lisp. Constructs such as objects in other languages can also be modeled with closures.   -- Wikipedia
Closures A closure is a block of code that you can manipulate and query In Ruby we call them blocks or Procs A block is a pure closure A Proc is a block wrapped as an object We generally use the terms block and Proc interchangeably
Closures multiplier = 5 block =  lambda  {|number| puts number * multiplier } A block An instance of Proc lambda() is a  method to convert blocks into Procs
Closures multiplier = 5 block =  lambda  {|number| puts number * multiplier } Parameter to the block
Closures multiplier = 5 block =  lambda  {|number| puts number * multiplier } Able to access variables  from outside the block
Proc’s multiplier = 5 block =  lambda  {|number| puts number * multiplier } block.call 2 block.arity prints 10 returns number of parameters that the block takes.  1 in this case
Blocks as parameters multiplier = 5 1.upto(3) {|number| puts number * multiplier } => 5 => 10 => 15 Same block as before Called once for each time through the loop
Alternate syntax multiplier = 5 1.upto(3) {|number| puts number * multiplier } 1.upto(3) do |number| puts number * multiplier end Equivalent
Why are closures significant? Presence of closures in a language completely changes the design of the libraries Closure based libraries generally result in significantly less code
// Read the lines and split them into columns List<String[]> lines=  new  ArrayList<String[]>(); BufferedReader reader =  null ; try  { reader =  new  BufferedReader( new  FileReader( &quot;people.txt&quot; )); String line = reader.readLine(); while ( line !=  null  ) { lines.add( line.split( &quot;\t&quot; ) ); } } finally  { if ( reader !=  null  ) { reader.close(); } } // then sort Collections.sort(lines,  new  Comparator<String[]>() { public   int  compare(String[] one, String[] two) { return  one[1].compareTo(two[1]); } }); // then write them back out BufferedWriter writer =  null ; try  { writer =  new  BufferedWriter(  new  FileWriter( &quot;people.txt&quot; ) ); for ( String[] strings : lines ) { StringBuilder builder =  new  StringBuilder(); for (  int  i=0; i<strings. length ; i++ ) { if ( i != 0 ) { builder.append( &quot;\t&quot; ); } builder.append(strings[i]); } } } finally  { if ( writer !=  null  ) { writer.close(); } } # Load the data lines = Array. new IO.foreach( 'people.txt' )  do  |line| lines << line.split end # Sort and write it back out File.open( 'people.txt' ,  'w' )  do  |file| lines.sort {|a,b| a[ 1 ] <=> b[ 1 ]}. each   do  |array| puts array.join( &quot;\t&quot; ) end end
Closure File Example file = File. new (fileName, 'w' ) begin file.puts ‘some content’ rescue file.close end
Closure File Example file = File. new (fileName, 'w' ) begin file.puts ‘some content’ rescue file.close end Only one line of business logic
Closure File Example file = File. new (fileName, 'w' ) begin file.puts ‘some content’ rescue file.close end File.open(fileName, 'w' )  do  |file| file.puts ‘some content’ end
Ruby file IO sample # Load the data lines = Array. new IO.foreach( 'people.txt' )  do  |line| lines << line.split end # Sort and write it back out File.open( 'people.txt' ,  'w' )  do  |file| lines.sort {|a,b| a[ 1 ] <=> b[ 1 ]}. each   do  |array| puts array.join( &quot;\t&quot; ) end end
Closure-like things in Java final  String name = getName(); new  Thread(  new  Runnable() { public   void  run() { doSomething(name); } }).start(); Only one line of business logic
Closures for Java? There are a couple of proposals being debated for Java7 Unclear whether any of them will be accepted In the past, Sun’s position has been that closures didn’t make sense at this point in Java’s evolution public static void main(String[] args) { int plus2(int x) { return x+2; } int(int) plus2b = plus2; System.out.println(plus2b(2)); }
Inheriting behaviour from multiple places C++ has multiple inheritance Java has interfaces Ruby has mixins
C++ : multiple inheritance
Java : inheritance
Ruby : mixins
Mixins Cannot be instantiated Can be mixed in
Enumerable class  Foo include  Enumerable def  each &block block.call 1 block.call 2 block.call 3 end end module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end
Enumerable class  Foo include  Enumerable def  each &block block.call 1 block.call 2 block.call 3 end end module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end
Enumerable Requires that the class implement each() For max, min and sort the <=> operator is also needed Adds many methods for modifying, searching, sorting the items all?, any?, collect, detect, each_cons, each_slice, each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, grep, include?, inject, map, max, member?, min, partition, reject, select, sort, sort_by, to_a, to_set, zip
Reopening classes class  Foo def  one puts  'one' end end
Reopening classes class  Foo def  one puts  'one' end end class  Foo def  two puts  'two' end end Reopening  the same class
Reopening classes class  Foo def  one puts  'one' end end class  Foo def  one puts  '1' end end Replacing, not adding a method
Reopening core classes class  String def  one puts  'one' end end We reopened  a CORE class and modified it
Metaprogramming Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually. -- Wikipedia
What changes can we make at runtime? Anything we can hand code, we can programmatically do Because of late binding, EVERYTHING happens at runtime
attr_accessor class  Foo attr_accessor  :bar end class  Foo def  bar @bar end def  bar=(newBar) @bar  = newBar end end Getter Setter
Possible implementation of attr_accessor class  Foo def  self.attr_accessor name module_eval <<-DONE def  #{name}() @ #{name} end def  #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor  :bar end
Possible implementation of attr_accessor class  Foo def  self.attr_accessor name module_eval <<-DONE def  #{name}() @ #{name} end def  #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor  :bar end “ Here Doc” Evaluates to  String
Possible implementation of attr_accessor class  Foo def  self.attr_accessor name module_eval <<-DONE def  #{name}() @ #{name} end def  #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor  :bar end String substitution
Possible implementation of attr_accessor class  Foo def  self.attr_accessor name module_eval <<-DONE def  #{name}() @ #{name} end def  #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor  :bar end Executes the string in the context of the class
Result class  Foo def  bar @bar end def  bar=(newBar) @bar  = newBar end end
ActiveRecord class  ListItem < ActiveRecord::Base belongs_to  :amazon_item acts_as_taggable acts_as_list  :scope  =>  :user end
Date :: once def  once(*ids)  # :nodoc: for  id  in  ids module_eval <<-&quot; end ;&quot;, __FILE__, __LINE__ alias_method  :__ #{id.to_i}__, :#{id.to_s} private  :__ #{id.to_i}__ def   #{id.to_s}(*args, &block) if  defined?  @__ #{id.to_i}__ @__ #{id.to_i}__ elsif  ! self.frozen? @__ #{id.to_i}__ ||= __#{id.to_i}__(*args, &block) else __ #{id.to_i}__(*args, &block) end end end ; end end
ObjectSpace ObjectSpace.each_object do |o|  puts o  end ObjectSpace.each_object(String) do |o|  puts o  end
ObjectSpace ObjectSpace.each_object do |o|  puts o  end ObjectSpace.each_object(String) do |o|  puts o  end All objects Only Strings
Continuations A snapshot of the call stack that the application can revert to at some point in the future
Why continuations? To save the state of the application across reboots of the VM To save the state of the application across requests to a web server Seaside (smalltalk) does this today
Downsides Only supported in one implementation of Ruby Will be removed from the language in Ruby 2.0
Implementations Ruby 1.8.x - “reference implementation” in C Ruby 1.9 - Next version of C interpreter Rubinius - Ruby in Ruby (sort-of) Cardinal - Ruby on Parrot Iron Ruby - Ruby on the DLR (Microsoft) Ruby.NET - Ruby on the CLR JRuby - Ruby on the JVM (Sun)
Implementations Ruby 1.8.x - “reference implementation” in C Ruby 1.9 - Next version of C interpreter Rubinius - Ruby in Ruby (sort-of) Cardinal - Ruby on Parrot Iron Ruby - Ruby on the DLR (Microsoft) Ruby.NET - Ruby on the CLR JRuby - Ruby on the JVM (Sun)
JRuby Runs on the Java Virtual Machine (JVM) Full implementation of the Ruby language Supported by Sun Runs many benchmarks faster than the 1.8 reference implementation (written in C) Able to easily call out to Java code
Ruby on Rails Web application framework Sweet spot - web application talking to a single relational database Allows very rapid development of web apps
Who’s using rails? Amazon • BBC • Cap Gemini  Chicago Tribune • Barclays • BPN • Cisco CNET  Electronic Arts • IBM • John Deere   JP Morgan Chase • LA Times • Limewire  Linked In • NASA • NBC • New York Times Oakley • Oracle • Orbitz • Turner Media twitter.com • Siemens • ThoughtWorks  Yahoo!
JRuby on Rails? Yes!  You can run a rails application on JRuby in a servlet container Goldspike is the servlet that dispatches to rails Tested on WebLogic, WebSphere, GlassFish, Jetty, Tomcat Warbler is the packaging tool that makes the WAR Supported on:  WebLogic, WebSphere, GlassFish, Jetty, Tomcat
Recap Learning a new language will make you better with all the languages you know Ruby has a much more concise syntax which means that it takes much less code to solve the same problems Ruby is able to run on the JVM which makes it an option for shops with heavy investments in J2EE infrastructure
Recap Everything is an object The language is extremely malleable New classes/methods can be created on the fly Existing classes can be modified at any time
Contacting me Mike Bowler [email_address] www.GargoyleSoftware.com  (co mpany) www.SphericalImpr ovement.com  (blog) Interested in le arning more about how Ruby a nd Java can coexist in your company?  Just ask me.

More Related Content

What's hot (13)

Ruby
RubyRuby
Ruby
Vladimir Bystrov
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
adamcookeuk
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
Anthony Brown
 
Ruby An Introduction
Ruby An IntroductionRuby An Introduction
Ruby An Introduction
Shrinivasan T
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
bryanbibat
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
Michael Koby
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
amiable_indian
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
ppt18
ppt18ppt18
ppt18
callroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
callroom
 
ppt9
ppt9ppt9
ppt9
callroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
callroom
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
adamcookeuk
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
Anthony Brown
 
Ruby An Introduction
Ruby An IntroductionRuby An Introduction
Ruby An Introduction
Shrinivasan T
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
bryanbibat
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
Michael Koby
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
amiable_indian
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
callroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
callroom
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 

Viewers also liked (20)

Ruby vs Java
Ruby vs JavaRuby vs Java
Ruby vs Java
Belighted
 
Ruby everywhere
Ruby everywhereRuby everywhere
Ruby everywhere
yukihiro_matz
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
Rémy-Christophe Schermesser
 
Java vs. Ruby
Java vs. RubyJava vs. Ruby
Java vs. Ruby
Bryan Rojas
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
Matt Aimonetti
 
Getting Started with Android Development
Getting Started with Android DevelopmentGetting Started with Android Development
Getting Started with Android Development
Edureka!
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
Wen-Tien Chang
 
«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»
Olga Lavrentieva
 
Seu site voando
Seu site voandoSeu site voando
Seu site voando
Maurício Linhares
 
Apresentação sobre JRuby
Apresentação sobre JRubyApresentação sobre JRuby
Apresentação sobre JRuby
Régis Eduardo Weizenmann Gregol
 
Beginner's Sinatra
Beginner's SinatraBeginner's Sinatra
Beginner's Sinatra
Tomokazu Kiyohara
 
Criação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao AgileCriação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao Agile
Robson Agapito Correa
 
Ruby OOP: Objects over Classes
Ruby OOP: Objects over ClassesRuby OOP: Objects over Classes
Ruby OOP: Objects over Classes
Aman King
 
Ruby's Object Model: Metaprogramming and other Magic
Ruby's Object Model: Metaprogramming and other MagicRuby's Object Model: Metaprogramming and other Magic
Ruby's Object Model: Metaprogramming and other Magic
Burke Libbey
 
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
GoIT
 
Continuous Delivery in Ruby
Continuous Delivery in RubyContinuous Delivery in Ruby
Continuous Delivery in Ruby
Brian Guthrie
 
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Marcio Sfalsin
 
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CloudIDSummit
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
Chamnap Chhorn
 
Advanced Ruby Idioms So Clean You Can Eat Off Of Them
Advanced Ruby Idioms So Clean You Can Eat Off Of ThemAdvanced Ruby Idioms So Clean You Can Eat Off Of Them
Advanced Ruby Idioms So Clean You Can Eat Off Of Them
Brian Guthrie
 
Ruby vs Java
Ruby vs JavaRuby vs Java
Ruby vs Java
Belighted
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
Matt Aimonetti
 
Getting Started with Android Development
Getting Started with Android DevelopmentGetting Started with Android Development
Getting Started with Android Development
Edureka!
 
«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»
Olga Lavrentieva
 
Criação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao AgileCriação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao Agile
Robson Agapito Correa
 
Ruby OOP: Objects over Classes
Ruby OOP: Objects over ClassesRuby OOP: Objects over Classes
Ruby OOP: Objects over Classes
Aman King
 
Ruby's Object Model: Metaprogramming and other Magic
Ruby's Object Model: Metaprogramming and other MagicRuby's Object Model: Metaprogramming and other Magic
Ruby's Object Model: Metaprogramming and other Magic
Burke Libbey
 
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
GoIT
 
Continuous Delivery in Ruby
Continuous Delivery in RubyContinuous Delivery in Ruby
Continuous Delivery in Ruby
Brian Guthrie
 
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Marcio Sfalsin
 
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CloudIDSummit
 
Advanced Ruby Idioms So Clean You Can Eat Off Of Them
Advanced Ruby Idioms So Clean You Can Eat Off Of ThemAdvanced Ruby Idioms So Clean You Can Eat Off Of Them
Advanced Ruby Idioms So Clean You Can Eat Off Of Them
Brian Guthrie
 
Ad

Similar to Ruby For Java Programmers (20)

Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Rails
elliando dias
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 
What I Love About Ruby
What I Love About RubyWhat I Love About Ruby
What I Love About Ruby
Keith Bennett
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
ppt7
ppt7ppt7
ppt7
callroom
 
ppt30
ppt30ppt30
ppt30
callroom
 
ppt21
ppt21ppt21
ppt21
callroom
 
ppt2
ppt2ppt2
ppt2
callroom
 
ppt17
ppt17ppt17
ppt17
callroom
 
test ppt
test ppttest ppt
test ppt
callroom
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
Benjamin Bock
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
Wen-Tien Chang
 
Ruby training day1
Ruby training day1Ruby training day1
Ruby training day1
Bindesh Vijayan
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
Gonçalo Silva
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Rails
elliando dias
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 
What I Love About Ruby
What I Love About RubyWhat I Love About Ruby
What I Love About Ruby
Keith Bennett
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
Benjamin Bock
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
Wen-Tien Chang
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
Gonçalo Silva
 
Ad

More from Mike Bowler (8)

Retrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile ConferenceRetrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile Conference
Mike Bowler
 
Retrospective science
Retrospective scienceRetrospective science
Retrospective science
Mike Bowler
 
Brain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean languageBrain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean language
Mike Bowler
 
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Mike Bowler
 
Continuous Delivery for Agile Teams
Continuous Delivery for Agile TeamsContinuous Delivery for Agile Teams
Continuous Delivery for Agile Teams
Mike Bowler
 
Inside Enumerable
Inside EnumerableInside Enumerable
Inside Enumerable
Mike Bowler
 
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Mike Bowler
 
Date Once
Date OnceDate Once
Date Once
Mike Bowler
 
Retrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile ConferenceRetrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile Conference
Mike Bowler
 
Retrospective science
Retrospective scienceRetrospective science
Retrospective science
Mike Bowler
 
Brain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean languageBrain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean language
Mike Bowler
 
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Mike Bowler
 
Continuous Delivery for Agile Teams
Continuous Delivery for Agile TeamsContinuous Delivery for Agile Teams
Continuous Delivery for Agile Teams
Mike Bowler
 
Inside Enumerable
Inside EnumerableInside Enumerable
Inside Enumerable
Mike Bowler
 
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Mike Bowler
 

Recently uploaded (20)

Kirill Klip GEM Royalty TNR Gold Copper Presentation
Kirill Klip GEM Royalty TNR Gold Copper PresentationKirill Klip GEM Royalty TNR Gold Copper Presentation
Kirill Klip GEM Royalty TNR Gold Copper Presentation
Kirill Klip
 
How to Quickly Hire Java Developers for Java App Development and IT Outsourci...
How to Quickly Hire Java Developers for Java App Development and IT Outsourci...How to Quickly Hire Java Developers for Java App Development and IT Outsourci...
How to Quickly Hire Java Developers for Java App Development and IT Outsourci...
Mobisoft Infotech
 
Cybersecurity for Business Students as a RESOURCE SPEAKER 2021
Cybersecurity for Business Students as a RESOURCE SPEAKER 2021Cybersecurity for Business Students as a RESOURCE SPEAKER 2021
Cybersecurity for Business Students as a RESOURCE SPEAKER 2021
MELJUN CORTES
 
Project - About Balloonerism the short film.
Project - About Balloonerism the short film.Project - About Balloonerism the short film.
Project - About Balloonerism the short film.
jyncxjrx7y
 
Understanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptx
Understanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptxUnderstanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptx
Understanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptx
Satya Mahesh Kallakuru
 
Corporate Wellness Market Share, Size & Growth Report (2025-2034)
Corporate Wellness Market Share, Size & Growth Report (2025-2034)Corporate Wellness Market Share, Size & Growth Report (2025-2034)
Corporate Wellness Market Share, Size & Growth Report (2025-2034)
janewatson684
 
Facemask Filter test .pdf
Facemask Filter test                .pdfFacemask Filter test                .pdf
Facemask Filter test .pdf
Test Master
 
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdfDr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group
 
Joint Field Work in Pharma - a Checklist for frontline Managers
Joint Field Work in Pharma - a Checklist for frontline ManagersJoint Field Work in Pharma - a Checklist for frontline Managers
Joint Field Work in Pharma - a Checklist for frontline Managers
Satya Mahesh Kallakuru
 
Aagami Corporate Presentation - June 2025
Aagami Corporate Presentation - June 2025Aagami Corporate Presentation - June 2025
Aagami Corporate Presentation - June 2025
Aagami, Inc.
 
Top Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdfTop Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdf
Hornet Dynamics
 
Deming_Recognition_Expanded_With_Notes.pptx
Deming_Recognition_Expanded_With_Notes.pptxDeming_Recognition_Expanded_With_Notes.pptx
Deming_Recognition_Expanded_With_Notes.pptx
RaulAmavisca
 
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)
Lviv Startup Club
 
How Does an Agentic AI Workflow Work? Here is Detail
How Does an Agentic AI Workflow Work? Here is DetailHow Does an Agentic AI Workflow Work? Here is Detail
How Does an Agentic AI Workflow Work? Here is Detail
yogi A
 
000000000000000000000000000000000001.pdf
000000000000000000000000000000000001.pdf000000000000000000000000000000000001.pdf
000000000000000000000000000000000001.pdf
hashimsaidiseki99
 
Daniel E. Kaplan - Dedication To Financial Excellence
Daniel E. Kaplan - Dedication To Financial ExcellenceDaniel E. Kaplan - Dedication To Financial Excellence
Daniel E. Kaplan - Dedication To Financial Excellence
Daniel E. Kaplan
 
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdfA Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
Innomantra
 
1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf
1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf
1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf
TanveerAhmed272451
 
Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...
Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...
Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...
RaulAmavisca
 
Mining Saudi Arabia Monthly Report May 2025
Mining Saudi Arabia Monthly Report May 2025Mining Saudi Arabia Monthly Report May 2025
Mining Saudi Arabia Monthly Report May 2025
Tendayi Mwayi
 
Kirill Klip GEM Royalty TNR Gold Copper Presentation
Kirill Klip GEM Royalty TNR Gold Copper PresentationKirill Klip GEM Royalty TNR Gold Copper Presentation
Kirill Klip GEM Royalty TNR Gold Copper Presentation
Kirill Klip
 
How to Quickly Hire Java Developers for Java App Development and IT Outsourci...
How to Quickly Hire Java Developers for Java App Development and IT Outsourci...How to Quickly Hire Java Developers for Java App Development and IT Outsourci...
How to Quickly Hire Java Developers for Java App Development and IT Outsourci...
Mobisoft Infotech
 
Cybersecurity for Business Students as a RESOURCE SPEAKER 2021
Cybersecurity for Business Students as a RESOURCE SPEAKER 2021Cybersecurity for Business Students as a RESOURCE SPEAKER 2021
Cybersecurity for Business Students as a RESOURCE SPEAKER 2021
MELJUN CORTES
 
Project - About Balloonerism the short film.
Project - About Balloonerism the short film.Project - About Balloonerism the short film.
Project - About Balloonerism the short film.
jyncxjrx7y
 
Understanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptx
Understanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptxUnderstanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptx
Understanding Pharma Revenue Recognition: Accounting Standards: Ind AS15.pptx
Satya Mahesh Kallakuru
 
Corporate Wellness Market Share, Size & Growth Report (2025-2034)
Corporate Wellness Market Share, Size & Growth Report (2025-2034)Corporate Wellness Market Share, Size & Growth Report (2025-2034)
Corporate Wellness Market Share, Size & Growth Report (2025-2034)
janewatson684
 
Facemask Filter test .pdf
Facemask Filter test                .pdfFacemask Filter test                .pdf
Facemask Filter test .pdf
Test Master
 
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdfDr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group
 
Joint Field Work in Pharma - a Checklist for frontline Managers
Joint Field Work in Pharma - a Checklist for frontline ManagersJoint Field Work in Pharma - a Checklist for frontline Managers
Joint Field Work in Pharma - a Checklist for frontline Managers
Satya Mahesh Kallakuru
 
Aagami Corporate Presentation - June 2025
Aagami Corporate Presentation - June 2025Aagami Corporate Presentation - June 2025
Aagami Corporate Presentation - June 2025
Aagami, Inc.
 
Top Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdfTop Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdf
Hornet Dynamics
 
Deming_Recognition_Expanded_With_Notes.pptx
Deming_Recognition_Expanded_With_Notes.pptxDeming_Recognition_Expanded_With_Notes.pptx
Deming_Recognition_Expanded_With_Notes.pptx
RaulAmavisca
 
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 2) (UA)
Lviv Startup Club
 
How Does an Agentic AI Workflow Work? Here is Detail
How Does an Agentic AI Workflow Work? Here is DetailHow Does an Agentic AI Workflow Work? Here is Detail
How Does an Agentic AI Workflow Work? Here is Detail
yogi A
 
000000000000000000000000000000000001.pdf
000000000000000000000000000000000001.pdf000000000000000000000000000000000001.pdf
000000000000000000000000000000000001.pdf
hashimsaidiseki99
 
Daniel E. Kaplan - Dedication To Financial Excellence
Daniel E. Kaplan - Dedication To Financial ExcellenceDaniel E. Kaplan - Dedication To Financial Excellence
Daniel E. Kaplan - Dedication To Financial Excellence
Daniel E. Kaplan
 
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdfA Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
Innomantra
 
1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf
1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf
1ɓbbbbbbbbbbbbbbbbbbbbbbbbbb. UCP600.pdf
TanveerAhmed272451
 
Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...
Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...
Vision, Mission, Purpose & Core Values: Leading with Clarity in a Time-Boxed ...
RaulAmavisca
 
Mining Saudi Arabia Monthly Report May 2025
Mining Saudi Arabia Monthly Report May 2025Mining Saudi Arabia Monthly Report May 2025
Mining Saudi Arabia Monthly Report May 2025
Tendayi Mwayi
 

Ruby For Java Programmers

  • 1. Ruby for Java Programmers Mike Bowler President, Gargoyle Software Inc.
  • 2. Why learn another language?
  • 4. Timeline: 1993 to 2000 Created in 1993 by Yukihiro &quot;Matz&quot; Matsumoto Ruby was popular in Japan but unknown everywhere else All documentation was written in Japanese
  • 5. Timeline: 2000-2004 First English language book published in 2000 A lot of interest in the Agile development community but mostly unknown elsewhere
  • 6. Timeline: 2004-today The Ruby on Rails framework has pushed ruby into the spotlight This is the “killer app”
  • 8. Terminology Early Late Static Dynamic Strong Weak
  • 9. Defining strong/weak typing Strong typing Objects are of a specific type and will not be converted automatically Java: “4”/2 results in a compile error Weak typing Objects can be converted under the covers at any time Perl: ‘4’/2 => 2 Ruby is strongly typed
  • 10. Early/late binding Early binding (aka static binding) All method invocations must be defined at compile time Java: foo.getUser() Late binding (aka dynamic binding) The runtime does not check that a given method exists until an attempt to invoke it Smalltalk: foo user. Ruby uses late binding
  • 11. Similarities Like Java, Ruby... runs on a virtual machine is garbage collected is object oriented (although to different degrees)
  • 12. Differences Everything is an object Java string = String.valueOf(1); Ruby string = 1.to_s() Primitive Object
  • 13. Differences Many things that you would expect to be keywords are actually methods throw new IllegalArgumentException( &quot;oops&quot; ); raise TypeError.new( &quot;oops&quot; ) Keywords Methods
  • 14. Differences Some syntax optional unless the result is ambiguous These statements are equivalent puts( &quot;foo&quot; ); puts &quot;foo&quot; Idiomatic (better) style
  • 15. Differences Classes are real objects They’re instances of Class Class methods can be overridden
  • 16. class ZebraCage < Cage attr_accessor :capacity @@allCages = Array. new def initialize maximumZebraCount @capacity = maximumZebraCount @@allCages << self end private def clean_cage # do some stuff here end end cage = ZebraCage. new 10 puts cage.capacity
  • 17. Multiline if if name. nil ? do_something end
  • 18. Multiline if if name. nil ? do_something end Notice the question mark
  • 19. With an else if name. nil ? do_something else something_else end
  • 20. Single line if if name. nil ? do_something end do_something if name. nil ?
  • 21. Both kinds of unless if name. nil ? do_something end do_something if name. nil ? unless name. nil ? do_something end do_something unless name. nil ?
  • 22. Dangerous methods name = &quot; foo &quot; name.strip name.strip! Returns a new string. Doesn’t modify name. Modifies name and returns that. Dangerous!
  • 23. Philosophy Java focuses on building blocks You can build whatever you want with the pieces Ruby focuses on solving problems Things you do frequently should be concise
  • 24. Initializing arrays List<String> list = new ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; );
  • 25. Same only ruby List<String> list = new ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); list = Array.new list << 'foo' list << 'bar'
  • 26. [] List<String> list = new ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); list = Array.new list << 'foo' list << 'bar' list = [ 'foo' , 'bar' ]
  • 27. %w() List<String> list = new ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); list = Array.new list << 'foo' list << 'bar' list = [ 'foo' , 'bar' ] list = %w(foo bar)
  • 28. In fairness to java... List<String> list = new ArrayList<String>(); list.add( &quot;foo&quot; ); list.add( &quot;bar&quot; ); List<String> list = Arrays.asList( &quot;foo&quot; , &quot;bar&quot; ); list = Array.new list << 'foo' list << 'bar' list = [ 'foo' , 'bar' ] list = %w(foo bar)
  • 29. Same idea with hashes Map<String,String> map = new HashMap<String,String>(); map.put( &quot;foo&quot; , &quot;one&quot; ); map.put( &quot;bar&quot; , &quot;two&quot; ); map = { 'foo' => 'one' , 'bar' => 'two' }
  • 30. Special case for Hash hash = { :a => 5 , :b => 3 } do_stuff 30 , hash do_stuff 100 , :a => 5 , :b => 3
  • 31. Regular Expressions Pattern pattern = Pattern.compile( &quot;^\\s*(.+)\\s*$&quot; ); Matcher matcher = pattern .matcher(line); if ( matcher.matches() ) { doSomething(); }
  • 32. Regular Expressions Pattern pattern = Pattern.compile( &quot;^\\s*(.+)\\s*$&quot; ); Matcher matcher = pattern .matcher(line); if ( matcher.matches() ) { doSomething(); } do_something if line =~ /^\s*(.+)\s*$/
  • 33. Nil and Null Java’s null Ruby’s nil Absence of an object An instance of NilClass if( a != null ) {...} unless a.nil? {...} null.toString() -> NPE nil.to_s -> “” null.getUser() -> Exception in thread &quot;main&quot; java.lang.NullPointerException nil.get_user -> NoMethodError: undefined method ‘get_user’ for nil:NilClass
  • 34. Implications of late binding Method dispatch is quite different Ruby makes a distinction between “messages” that are sent to an object and the “methods” that get dispatched
  • 36. What if there isn’t a method for the specified message?
  • 37. method_missing example from ActiveRecord user = Users.find_by_name(name) user = Users.find( :first , :conditions => [ &quot;name = ?&quot; , name])
  • 38. Creating proxy objects Mock object for testing Proxy object to allow distributed objects across machines Wrapper to record usage of a given object
  • 39. Implementing a proxy class Proxy def method_missing name, *args, &proc puts name,args end end
  • 40. Implementing a proxy class Proxy def method_missing name, *args, &proc puts name,args end end Proxy. new .foo_bar ‘a’ Proxy. new .to_s Dispatches to method_missing Doesn’t go to method_missing
  • 41. Overriding to_s class Proxy def method_missing name, *args, &proc puts name,args end def to_s method_missing :to_s, [] end end
  • 42. = • === • =~ • __id__ • _send__ • class • clone • dclone display • dup • enum_for • eql? • equal? • extend freeze frozen? • hash • id • inspect • instance_eval instance_of? instance_variable_defined • instance_variable_get instance_variable_get • instance_variable_set instance_variable_set • instance_variables • is_a? kind_of? • method • methods • new • nil? • object_id p rivate_methods • protected_methods • public_methods remove_instance_variable • respond_to? • send singleton_method_added • singleton_method_removed singleton_method_undefined • singleton_methods • taint tainted? • to_a • to_enum • to_s • to_yaml to_yaml_properties • to_yaml_style • type • untaint
  • 43. Implementing a proxy class Proxy instance_methods.each do |method| undef_method method unless method =~ /^__/ end def method_missing name, *args, &proc puts name,args end end Proxy. new .to_s
  • 44. Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things. — Doug Gwyn
  • 45. Cultural differences about type Java is very focused on the types of objects Is the object an instance of a specific class? Or does it implement a specific interface? Ruby is focused on the behaviour Does the object respond to a given message?
  • 46. Types public void foo( ArrayList list ) { list.add( &quot;foo&quot; ); } def foo list list << 'foo' end What’s the type? What’s the type?
  • 47. Duck typing def foo list list << 'foo' end If list is a String => ‘foo’ If list is an Array => [‘foo’] If list is an IO => string will be written to stream
  • 48. Duck typing Duck typing implies that an object is interchangeable with any other object that implements the same interface, regardless of whether the objects have a related inheritance hierarchy. -- Wikipedia &quot;If it walks like a duck and quacks like a duck, it must be a duck.&quot; -- Pragmatic Dave Thomas
  • 49. How does this change how we think of types? think of types? think of types?
  • 50. Overflow conditions int a = Integer. MAX_VALUE ; System. out .println( &quot; a=&quot; +a); System. out .println( &quot;a+1=&quot; +(a+1)); a=2147483647 a+1= ??
  • 51. Overflow conditions int a = Integer. MAX_VALUE ; System. out .println( &quot; a=&quot; +a); System. out .println( &quot;a+1=&quot; +(a+1)); a=2147483647 a+1=-2147483648 oops
  • 52. Overflow in ruby? number = 1000 1 .upto( 4 ) do puts &quot;#{number.class} #{number}&quot; number = number * number end Fixnum 1000 Fixnum 1000000 Bignum 1000000000000 Bignum 1000000000000000000000000
  • 53. Closures A closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables. The explicit use of closures is associated with functional programming and with languages such as ML and Lisp. Constructs such as objects in other languages can also be modeled with closures. -- Wikipedia
  • 54. Closures A closure is a block of code that you can manipulate and query In Ruby we call them blocks or Procs A block is a pure closure A Proc is a block wrapped as an object We generally use the terms block and Proc interchangeably
  • 55. Closures multiplier = 5 block = lambda {|number| puts number * multiplier } A block An instance of Proc lambda() is a method to convert blocks into Procs
  • 56. Closures multiplier = 5 block = lambda {|number| puts number * multiplier } Parameter to the block
  • 57. Closures multiplier = 5 block = lambda {|number| puts number * multiplier } Able to access variables from outside the block
  • 58. Proc’s multiplier = 5 block = lambda {|number| puts number * multiplier } block.call 2 block.arity prints 10 returns number of parameters that the block takes. 1 in this case
  • 59. Blocks as parameters multiplier = 5 1.upto(3) {|number| puts number * multiplier } => 5 => 10 => 15 Same block as before Called once for each time through the loop
  • 60. Alternate syntax multiplier = 5 1.upto(3) {|number| puts number * multiplier } 1.upto(3) do |number| puts number * multiplier end Equivalent
  • 61. Why are closures significant? Presence of closures in a language completely changes the design of the libraries Closure based libraries generally result in significantly less code
  • 62. // Read the lines and split them into columns List<String[]> lines= new ArrayList<String[]>(); BufferedReader reader = null ; try { reader = new BufferedReader( new FileReader( &quot;people.txt&quot; )); String line = reader.readLine(); while ( line != null ) { lines.add( line.split( &quot;\t&quot; ) ); } } finally { if ( reader != null ) { reader.close(); } } // then sort Collections.sort(lines, new Comparator<String[]>() { public int compare(String[] one, String[] two) { return one[1].compareTo(two[1]); } }); // then write them back out BufferedWriter writer = null ; try { writer = new BufferedWriter( new FileWriter( &quot;people.txt&quot; ) ); for ( String[] strings : lines ) { StringBuilder builder = new StringBuilder(); for ( int i=0; i<strings. length ; i++ ) { if ( i != 0 ) { builder.append( &quot;\t&quot; ); } builder.append(strings[i]); } } } finally { if ( writer != null ) { writer.close(); } } # Load the data lines = Array. new IO.foreach( 'people.txt' ) do |line| lines << line.split end # Sort and write it back out File.open( 'people.txt' , 'w' ) do |file| lines.sort {|a,b| a[ 1 ] <=> b[ 1 ]}. each do |array| puts array.join( &quot;\t&quot; ) end end
  • 63. Closure File Example file = File. new (fileName, 'w' ) begin file.puts ‘some content’ rescue file.close end
  • 64. Closure File Example file = File. new (fileName, 'w' ) begin file.puts ‘some content’ rescue file.close end Only one line of business logic
  • 65. Closure File Example file = File. new (fileName, 'w' ) begin file.puts ‘some content’ rescue file.close end File.open(fileName, 'w' ) do |file| file.puts ‘some content’ end
  • 66. Ruby file IO sample # Load the data lines = Array. new IO.foreach( 'people.txt' ) do |line| lines << line.split end # Sort and write it back out File.open( 'people.txt' , 'w' ) do |file| lines.sort {|a,b| a[ 1 ] <=> b[ 1 ]}. each do |array| puts array.join( &quot;\t&quot; ) end end
  • 67. Closure-like things in Java final String name = getName(); new Thread( new Runnable() { public void run() { doSomething(name); } }).start(); Only one line of business logic
  • 68. Closures for Java? There are a couple of proposals being debated for Java7 Unclear whether any of them will be accepted In the past, Sun’s position has been that closures didn’t make sense at this point in Java’s evolution public static void main(String[] args) { int plus2(int x) { return x+2; } int(int) plus2b = plus2; System.out.println(plus2b(2)); }
  • 69. Inheriting behaviour from multiple places C++ has multiple inheritance Java has interfaces Ruby has mixins
  • 70. C++ : multiple inheritance
  • 73. Mixins Cannot be instantiated Can be mixed in
  • 74. Enumerable class Foo include Enumerable def each &block block.call 1 block.call 2 block.call 3 end end module Enumerable def collect array = [] each do |a| array << yield (a) end array end end
  • 75. Enumerable class Foo include Enumerable def each &block block.call 1 block.call 2 block.call 3 end end module Enumerable def collect array = [] each do |a| array << yield (a) end array end end
  • 76. Enumerable Requires that the class implement each() For max, min and sort the <=> operator is also needed Adds many methods for modifying, searching, sorting the items all?, any?, collect, detect, each_cons, each_slice, each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, grep, include?, inject, map, max, member?, min, partition, reject, select, sort, sort_by, to_a, to_set, zip
  • 77. Reopening classes class Foo def one puts 'one' end end
  • 78. Reopening classes class Foo def one puts 'one' end end class Foo def two puts 'two' end end Reopening the same class
  • 79. Reopening classes class Foo def one puts 'one' end end class Foo def one puts '1' end end Replacing, not adding a method
  • 80. Reopening core classes class String def one puts 'one' end end We reopened a CORE class and modified it
  • 81. Metaprogramming Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually. -- Wikipedia
  • 82. What changes can we make at runtime? Anything we can hand code, we can programmatically do Because of late binding, EVERYTHING happens at runtime
  • 83. attr_accessor class Foo attr_accessor :bar end class Foo def bar @bar end def bar=(newBar) @bar = newBar end end Getter Setter
  • 84. Possible implementation of attr_accessor class Foo def self.attr_accessor name module_eval <<-DONE def #{name}() @ #{name} end def #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor :bar end
  • 85. Possible implementation of attr_accessor class Foo def self.attr_accessor name module_eval <<-DONE def #{name}() @ #{name} end def #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor :bar end “ Here Doc” Evaluates to String
  • 86. Possible implementation of attr_accessor class Foo def self.attr_accessor name module_eval <<-DONE def #{name}() @ #{name} end def #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor :bar end String substitution
  • 87. Possible implementation of attr_accessor class Foo def self.attr_accessor name module_eval <<-DONE def #{name}() @ #{name} end def #{name}=(newValue) @ #{name} = newValue end DONE end my_attr_accessor :bar end Executes the string in the context of the class
  • 88. Result class Foo def bar @bar end def bar=(newBar) @bar = newBar end end
  • 89. ActiveRecord class ListItem < ActiveRecord::Base belongs_to :amazon_item acts_as_taggable acts_as_list :scope => :user end
  • 90. Date :: once def once(*ids) # :nodoc: for id in ids module_eval <<-&quot; end ;&quot;, __FILE__, __LINE__ alias_method :__ #{id.to_i}__, :#{id.to_s} private :__ #{id.to_i}__ def #{id.to_s}(*args, &block) if defined? @__ #{id.to_i}__ @__ #{id.to_i}__ elsif ! self.frozen? @__ #{id.to_i}__ ||= __#{id.to_i}__(*args, &block) else __ #{id.to_i}__(*args, &block) end end end ; end end
  • 91. ObjectSpace ObjectSpace.each_object do |o| puts o end ObjectSpace.each_object(String) do |o| puts o end
  • 92. ObjectSpace ObjectSpace.each_object do |o| puts o end ObjectSpace.each_object(String) do |o| puts o end All objects Only Strings
  • 93. Continuations A snapshot of the call stack that the application can revert to at some point in the future
  • 94. Why continuations? To save the state of the application across reboots of the VM To save the state of the application across requests to a web server Seaside (smalltalk) does this today
  • 95. Downsides Only supported in one implementation of Ruby Will be removed from the language in Ruby 2.0
  • 96. Implementations Ruby 1.8.x - “reference implementation” in C Ruby 1.9 - Next version of C interpreter Rubinius - Ruby in Ruby (sort-of) Cardinal - Ruby on Parrot Iron Ruby - Ruby on the DLR (Microsoft) Ruby.NET - Ruby on the CLR JRuby - Ruby on the JVM (Sun)
  • 97. Implementations Ruby 1.8.x - “reference implementation” in C Ruby 1.9 - Next version of C interpreter Rubinius - Ruby in Ruby (sort-of) Cardinal - Ruby on Parrot Iron Ruby - Ruby on the DLR (Microsoft) Ruby.NET - Ruby on the CLR JRuby - Ruby on the JVM (Sun)
  • 98. JRuby Runs on the Java Virtual Machine (JVM) Full implementation of the Ruby language Supported by Sun Runs many benchmarks faster than the 1.8 reference implementation (written in C) Able to easily call out to Java code
  • 99. Ruby on Rails Web application framework Sweet spot - web application talking to a single relational database Allows very rapid development of web apps
  • 100. Who’s using rails? Amazon • BBC • Cap Gemini Chicago Tribune • Barclays • BPN • Cisco CNET Electronic Arts • IBM • John Deere JP Morgan Chase • LA Times • Limewire Linked In • NASA • NBC • New York Times Oakley • Oracle • Orbitz • Turner Media twitter.com • Siemens • ThoughtWorks Yahoo!
  • 101. JRuby on Rails? Yes! You can run a rails application on JRuby in a servlet container Goldspike is the servlet that dispatches to rails Tested on WebLogic, WebSphere, GlassFish, Jetty, Tomcat Warbler is the packaging tool that makes the WAR Supported on: WebLogic, WebSphere, GlassFish, Jetty, Tomcat
  • 102. Recap Learning a new language will make you better with all the languages you know Ruby has a much more concise syntax which means that it takes much less code to solve the same problems Ruby is able to run on the JVM which makes it an option for shops with heavy investments in J2EE infrastructure
  • 103. Recap Everything is an object The language is extremely malleable New classes/methods can be created on the fly Existing classes can be modified at any time
  • 104. Contacting me Mike Bowler [email_address] www.GargoyleSoftware.com (co mpany) www.SphericalImpr ovement.com (blog) Interested in le arning more about how Ruby a nd Java can coexist in your company? Just ask me.