Your SlideShare is downloading. ×
Ruby 1.9
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ruby 1.9

2,648
views

Published on

The Ruby 1.9 presentation I gave before the ATL RUG.

The Ruby 1.9 presentation I gave before the ATL RUG.

Published in: Technology, Education

1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,648
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
91
Comments
1
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. += 0.1 require ‘yarv’ require ‘syntax-1.9’ require ‘stdlib-1.9’ require ‘unicode’ Stephen Touset <stephen@touset.org>
  • 2. Play Along at Home $ svn export http://svn.ruby-lang.org/repos/ruby/tags/v1_9_9_0 ruby-1.9.0 $ cd ruby-1.9.0 $ ./configure --program-suffix 1.9 $ make $ make test $ chmod a+x bin/irb $ PATH=. RUBYLIB=quot;./libquot; bin/irb
  • 3. YARV FTW • Faster • Less Memory • Native threads* • Fun Acronym *concurrency of one
  • 4. ruby 1.8 ruby 1.9 improvement app_answer 0.460 0.146 68% app_erb 1.655 1.646 0.5% app_factorial 0.762 0.858 -13% app_fib 5.572 1.530 73% app_mandelbrot 2.034 0.848 58% app_pentomino 92.811 50.778 45% app_raise 1.984 2.474 -25% app_strcat 1.414 1.113 21% app_tak 8.306 2.083 75% app_tarai 6.530 1.660 75% app_uri 3.555 2.027 43%
  • 5. ≈38% faster (62% as slow) ((twice-ish as fast))
  • 6. Yet Another Meaningless Benchmark (http://www.timestretch.com/FractalBenchmark.html)
  • 7. The Image Below is Not Photoshopped
  • 8. ...thus ending the language wars once and for all
  • 9. Shiny New Syntax • Lambda shortcut • Implicit #call • Literal hashes • Block parameters • Function parameter insanity • Block local variables
  • 10. lambda, v1.9 ->
  • 11. λ
  • 12. _ /|
  • 13. _ /|
  • 14. ->
  • 15. λ -> “I found lambda!” - Matz
  • 16. c = lambda {|a, b| [b, a] } - becomes - c = ->(a, b) { [b, a] }
  • 17. Implicit #call c = lambda {|a, b| [b, a] } c.call(1, 2) - becomes - c = ->(a, b) { [b, a] } c.(1,2)
  • 18. Block Parameters lambda {|a, b, c = 1, &d| d.call } ^ syntax error, unexpected '}' ... - becomes - ->(a, b, c = 1, &d) { d.call }
  • 19. laaaaame lambda { yield }.call { puts ‘hi’ } LocalJumpError: no block given - becomes - -> { yield }.() { puts ‘hi’ } LocalJumpError: no block given
  • 20. Literal Hashes { :a => 1, :b => 2, :c => 3, :d => 4 } - becomes - { a: 1, b: 2, c: 3, d: 4 }
  • 21. W...T... def foo(a, b = 100, c) puts “#{a} #{b} #{c}” end foo(3) # => ArgumentError foo(3, 5) # => 3, 100, 5 foo(3, 4, 5) # => 3, 4, 5
  • 22. ...F def bar(a, b = nil, *c, d) end
  • 23. Block Local Variables i = Elephant.new [1,2,3].map {|i| i * 2 } i # => #<Elephant:0x3688b4>
  • 24. stdlib.succ! • send no longer calls private methods • #methods and its siblings return symbols • class variables are not inherited, now work like class instance variables (thus obsoleting my entire metaprogramming presentation) • blocks passable to #[] • enumerator love • Oniguruma regexp engine
  • 25. #tap that class Passes an object to a block, then returns the object (useful for call chaining) ‘foo’.tap(&:upcase!).tap {|s| s.gsub! /oo/, ‘u’ }
  • 26. Wait, did I see that correctly? tap(&:upcase!) ^^
  • 27. Enumerator Love [1, 2, 3].cycle {|i| puts i } # loops forever puts-ing 1,2,3 [1, 2, 3].first(2) # => [1,2] [1, 2, 3].map.with_index {|o,i| i} # => [0, 1, 2] [1, 3, 4, 2].take {|i| i < 4 } # => [1, 3] [1, 2, 3].reduce(:+1) # => 6
  • 28. Ordered Hashes h = { a: 1, b: 2, c: 3 } h # => { a: 1, b: 2, c: 3 } h.keys # => [ :a, :b, :c ] h.values # => [ 1, 2, 3 ]
  • 29. Encoded Strings • No longer Enumerable • String#bytes • String#lines • String#each_char • “One-char-wide” String behavior
  • 30. #!/usr/bin/ruby -w # -*- coding: utf-8 -*- open(filename, ‘r:utf-8’) encodings = %w{ utf-8 utf-16 ascii-8bit euc-jp }
  • 31. More Info • Summary of Changes in 1.9 http://eigenclass.org/hiki/Changes+in+Ruby+1.9 • Mechanically Verified 1.9 Changelog http://eigenclass.org/hiki/mechanically-verified-ruby19-changelog • Matz’ RubyConf 2007 Keynote http://rubyconf2007.confreaks.com/d2t1p8_keynote.html
  • 32. exit(0)

×