Quick Intro To JRuby

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites & 1 Group

    Quick Intro To JRuby - Presentation Transcript

    1. A (Quick) Introduction to JRuby Frederic Jean fred@fredjean.net
    2. Hello JRuby
    3. Develop, Deploy, Build, Test, Monitor Configuration DSLs Glue, Wiring External System Integration Dynamic Layer Application Code Stable Layer Java, Statically typed Legacy libraries
    4. Ruby
    5. Ruby is... • Dynamically Typed • Strongly Typed • Everything is An Object
    6. (Almost) Everything is an Object
    7. Ruby Literals # Strings \"This is a String\" 'This is also a String' %{So is this} # Numbers 1, 0xa2, 0644, 3.14, 2.2e10 # Arrays and Hashes ['John', 'Henry', 'Mark'] { :hello => \"bonjour\", :bye => \"au revoir\"} # Regular Expressions \"Mary had a little lamb\" =~ /little/ \"The London Bridge\" =~ %r{london}i # Ranges (1..100) # inclusive (1...100) # exclusive
    8. Symbols :symbol • String-like construct • Only one copy in memory
    9. Blocks ['John', 'Henry', 'Mark'].each { |name| puts \"#{name}\"} File.open(\"/tmp/password.txt\") do |input| text = input.read end
    10. Ruby Classes class Person attr_accessor :name, :title end p = Person.new
    11. Open Classes class Fixnum def odd? self % 2 == 1 end def even? self % 2 == 0 end end http://localhost:4567/code/fixnum.rb
    12. Mixins module Parity def even? self % 2 == 0 end def odd? self % 2 == 1 end end http://localhost:4567/code/parity.rb
    13. Mixins class Person include Enumerable attr_accessor :first_name, :last_name def initialize(first_name, last_name) @first_name = first_name @last_name = last_name end def <=>(other) if self.last_name == other.last_name self.first_name <=> other.first_name else self.last_name <=> other.last_name end end def to_s \"#{first_name} #{last_name}\" end end http://localhost:4567/code/sorting.rb
    14. JRuby
    15. JRuby • Ruby Implementation on the JVM • Compatible with Ruby 1.8.6 • Native Multithreading • Full Access to Java Libraries
    16. JRuby Hello World java.lang.System.out.println \"Hello JRuby!\" http://localhost:4567/code/jruby_hello.rb
    17. Java Integration require 'java'
    18. JI: Ruby-like Methods Java Ruby Locale.US Locale::US System.currentTimeMillis() System.current_time_millis locale.getLanguage() locale.language date.getTime() date.time date.setTime(10) date.time = 10 file.isDirectory() file.directory?
    19. JI: Java Extensions h = java.util.HashMap.new h[\"key\"] = \"value\" h[\"key\"] # => \"value\" h.get(\"key\") # => \"value\" h.each {|k,v| puts k + ' => ' + v} # key => value h.to_a # => [[\"key\", \"value\"]] http://localhost:4567/code/ji/extensions.rb
    20. JI: Java Extensions module java::util::Map include Enumerable def each(&block) entrySet.each { |pair| block.call([pair.key, pair.value]) } end def [](key) get(key) end def []=(key,val) put(key,val) val end end
    21. JI: Open Java Classes class Java::JavaLang::Integer def even? int_value % 2 == 0 end def odd? int_value % 2 == 1 end end http://localhost:4567/code/ji/integer.rb
    22. JI: Interface Conversion package java.util.concurrent; public class Executors { // ... public static Callable callable(Runnable r) { // ... } }
    23. JI: Interface Conversion class SimpleRubyObject def run puts \"hi\" end end callable = Executors.callable(SimpleRubyObject.new) callable.call http://localhost:4567/code/ji/if_conversion.rb
    24. JI: Closure Conversion callable = Executors.callable { puts \"hi\" } callable.call http://localhost:4567/code/ji/closure_conversion.rb
    25. Develop, Deploy, Build, Test, Monitor Configuration DSLs Glue, Wiring External System Integration Dynamic Layer Application Code Stable Layer Java, Statically typed Legacy libraries
    26. Usage • Runtime • Wrapper around Java Code • Calling From Java • Utilities
    27. JRuby as a Runtime
    28. JRuby on Rails • Wrap Rails app into a war file • Direct support in Glassfish v3 Prelude • http://kenai.com • http://mediacast.sun.com
    29. webmate require 'rubygems' require 'sinatra' get '/*' do file, line = request.path_info.split(/:/) local_file = File.join(Dir.pwd, file) if (File.exists?(local_file)) redirect \"txmt://open/?url=file://#{local_file}&line=#{line}\" else not_found end end http://localhost:4567/code/webmate.rb
    30. Wrapping Java Code
    31. Swing Applications frame = JFrame.new(\"Hello Swing\") • Reduce verbosity • Simplify event handlers http://localhost:4567/code/swing.rb
    32. RSpec Testing Java describe \"An empty\", HashMap do before :each do @hash_map = HashMap.new end it \"should be able to add an entry to it\" do @hash_map.put \"foo\", \"bar\" @hash_map.get(\"foo\").should == \"bar\" end end JTestr Provides Ant and Maven integration http://jtestr.codehaus.org http://localhost:4567/code/hashmap_spec.rb
    33. Utilities
    34. Develop, Deploy, Build, Test, Monitor Configuration DSLs Glue, Wiring External System Integration Dynamic Layer Application Code Stable Layer Java, Statically typed Legacy libraries
    35. Build Utilities • Rake • Raven • Buildr
    36. Conclusion
    37. Resources • http://jruby.org • http://wiki.jruby.org • http://jruby.kenai.com • http://jtester.codehaus.org • http://raven.rubyforge.org • http://buildr.apache.org

    + fredjeanfredjean, 7 months ago

    custom

    473 views, 3 favs, 2 embeds more stats

    A shorter version of my Introduction to JRuby talk more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 473
      • 463 on SlideShare
      • 10 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 7
    Most viewed embeds
    • 6 views on http://fredjean.net
    • 4 views on http://blog.fredjean.net

    more

    All embeds
    • 6 views on http://fredjean.net
    • 4 views on http://blog.fredjean.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories