Ruby 1.9

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.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

2 Favorites & 1 Group

Ruby 1.9 - Presentation 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=\"./lib\" 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)

+ guestaef7eaguestaef7ea, 2 years ago

custom

1402 views, 2 favs, 0 embeds more stats

The Ruby 1.9 presentation I gave before the ATL RUG more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 1402
    • 1402 on SlideShare
    • 0 from embeds
  • Comments 1
  • Favorites 2
  • Downloads 57
Most viewed embeds

more

All embeds

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

Tags

Groups / Events