Upload
gautam-kumar
View
3.655
Download
0
Embed Size (px)
Citation preview
Java vs Ruby
Java
Ruby
1 class Foo{2 public static void main (String []args){3 }4 }
The Minimum Program
Java vs Ruby
Java
Ruby
1 class Foo{ 2 private int bar1 , bar2; 3 public int getBar1(){ return this.bar1; } 4 public int getBar2(){ return this.bar2; } 5 public void setBar2(int bar2){ 6 this.bar2=bar2; 7 } 8 public void setBar1(int bar1){ 9 this.bar1=bar1;10 }11 }
1 class Foo2 attr_accessor :bar1 , :bar23 end
Getters and Setters
Java vs Ruby
Java
Ruby
1 List<String> friends = new LinkedList<String>();2 List<String> enemies = new LinkedList<String>();3 friends.add("Java"); friends.add("JRuby");4 friends.add("Jython"); friends.add("Scala")5 enemies.add("C#"); enemies.add("IronRuby");6 enemies.add("IronPython"); enemies.add("F#");
1 friends=[]2 enemies=[]3 friends<< "Java" << "JRuby" << "Jython" << "Scala"4 enemies<< "c#" << "IronRuby" << "IronPython" << "F#"
Working with Lists
Everything is an object (Literally !!)
1 3.times { puts "Microsoft is Evil" }2 Microsoft is Evil3 Microsoft is Evil4 Microsoft is Evil5 => 3 jruby-1.6.5 :011 > "Something".class => String jruby-1.6.5 :012 > 22.class => Fixnum
Getting JRuby
Method 1:● Install MRI and RVM from
○ Package manager (Linux only)○ ruby-lang.org
● Then do "rvm install jruby"
Using java classes in Jruby1 include Java 2 java_import java.lang.Thread 3 java_import java.lang.System 4 class SomeClass 5 include java.lang.Runnable 6 def run 7 5.times do 8 System.out.println "Executing Thread : #{Thread.current_thread.get_id}" 9 end10 end11 end12 5.times{13 Thread.new(SomeClass.new).start14 }
Now onto Sinatra
● Sinatra is a DSL for quickly creating web-apps with Ruby
● http://sinatrarb.com ● Best Installed as "gem install sinatra"
Sinatra saying Hello
1 require 'rubygems'2 require 'sinatra'3 require 'data_mapper'4 set :bind , '0.0.0.0'5 get '/' do6 "Hello there this is Frank Sinatra from beyond the grave"7 end