O que tem de novo noRuby 2?               Fabio Akita              @akitaonrails          codeminer42.com
Ruby 0.95   Dez 1995Ruby 1.8    Ago 2003Rails 0.8   Dez 2005Ruby 1.9    Dez 2007
Ruby 0.95   Dez 1995Ruby 1.8    Ago 2003Rails 0.8   Dez 2005Ruby 1.9    Dez 2007
Ruby 0.95   Dez 1995Ruby 1.8    Ago 2003Rails 0.8   Dez 2005Ruby 1.9    Dez 2007
Ruby 0.95   Dez 1995Ruby 1.8    Ago 2003Rails 0.8   Dez 2005Ruby 1.9    Dez 2007
Ruby 2.0  24 de Fevereiro de 2013
Compatível com 1.9
Literal Symbol List
> %q[hello world]=> "hello world"> %i[hello world]=> [:hello, :world]
Keyword Arguments
def foo(options = {})  param1 = options[:param1]  param2 = options[:param2]  return [param1, param2]end> foo param1: "Hell...
def foo(param1: nil, param2: nil)  return [param1, param2]end> foo param1: "Hello", param2: "World"=> ["Hello", "World"]
Module Prepend
> [1,2,3].to_s=> "[1, 2, 3]"
module Foo  def self.included(base)    base.class_eval do      alias_method :original_to_s, :to_s      def to_s        ori...
> [1,2,3].to_s=> "[1, 2, 3], Foo"> Array.ancestors=> [Array, Foo, Enumerable, Object, Kernel,BasicObject]
module Foo  def to_s    super + ", Foo"  endendclass Array  prepend Fooend
> [1,2,3].to_s=> "[1, 2, 3], Foo"> Array.ancestors=> [Foo, Array, Enumerable, Object, Kernel,BasicObject]
Lazy Enumerators
> a = (0..3).map { |i| i }=> [0, 1, 2, 3]
> a = (0..3).lazy.map { |i| i }=> #<Enumerator::Lazy: #<Enumerator::Lazy: 0..3>:map>> a.next=> 0> a.next=> 1> a.next=> 2> ...
> a = (0..Float::INFINITY).lazy.map { |i| i }=> #<Enumerator::Lazy: #<Enumerator::Lazy:0..Infinity>:map>> a.next=> 0> a.ne...
Refinements
module Foo  def hello    "Hello, #{to_s}"  endendclass Array  include Fooend> [1,2,3].hello=> "Hello, [1, 2, 3]"
module Foo  refine Array do    def hello      "Hello, #{to_s}"    end  endendusing Foo> [1,2,3].hello=> "Hello, [1, 2, 3]"
module Foo               def bah  refine Array do          [1,2,3].hello    def hello            end      "Hello, #{to_s}"...
http://rvm.io
curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled
http://gembundler.com/
BrowserNGINXWorker Linux
BrowserNGINXWorker Linux
BrowserNGINXWorker Ruby Linux
BrowserNGINXWorker Rails Ruby Linux
BrowserNGINXWorker Rails Ruby Linux
Browser   Browser           Browser   Browser                    NGINXWorker    Worker            Worker    Worker Rails  ...
Browser   Browser           Browser   Browser                    NGINXWorker    Worker            Worker    Worker Rails  ...
M&SMark & Sweep GC
struct RBasic {    VALUE flags;   RString                    flags    VALUE klass;    klass};
RString   RString   RString flags     flags     flags klass     klass     klass
RString   RString   RString flags     flags     flags klass     klass     klass          fork()
RString   RString   RString flags     flags     flags klass     klass     klass          fork()
RString    RString     RString flags       flags      flags klass       klass      klass          GC.start()RString    RSt...
OOBW Out of Band Work
LazyLazy Sweep GC - Ruby 1.9.3
“CoW” Copy on Write
RString   RString   RString flags     flags     flags klass     klass     klass
RString   RString   RString flags     flags     flags klass     klass     klass
RString   RString   RString flags     flags     flags klass     klass     klass
RString   RString   RString flags     flags     flags klass     klass     klass
fork()
GC.start
BitmapBitmap Marking GC - Ruby 2.0
9   000010018   000010007   00000111
9   000010018   000010007   00000111
9   000010018   000010007   00000111
00000001   2^0   1     User00000010   2^1   2   Moderator00000100   2^2   4 Administrator
00000001   2^0   1     User00000010   2^1   2   Moderator00000100   2^2   4 Administrator
00000001   2^0   1     User00000010   2^1   2   Moderator00000100   2^2   4 Administrator
1   1   1   0   0   0   0   0   0   0   0
1   1   1   0   0   0   0   0   0   0   0                                            fork()
fork()
fork()
Browser   Browser           Browser   Browser                    NGINXWorker    Worker            Worker    Worker Rails  ...
Browser     Browser          Browser               Browser                    Browser                         Browser     ...
Browser     Browser          Browser               Browser                    Browser                         Browser     ...
Rails 3.2.12+  Rails 4.0
Thanks! @akitaonrails
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
Upcoming SlideShare
Loading in …5
×

O que tem de novo no Ruby 2.0?

18,518 views

Published on

Palestra apresentada no evento "Don't Panic"

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
18,518
On SlideShare
0
From Embeds
0
Number of Embeds
15,711
Actions
Shares
0
Downloads
36
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

O que tem de novo no Ruby 2.0?

  1. 1. O que tem de novo noRuby 2? Fabio Akita @akitaonrails codeminer42.com
  2. 2. Ruby 0.95 Dez 1995Ruby 1.8 Ago 2003Rails 0.8 Dez 2005Ruby 1.9 Dez 2007
  3. 3. Ruby 0.95 Dez 1995Ruby 1.8 Ago 2003Rails 0.8 Dez 2005Ruby 1.9 Dez 2007
  4. 4. Ruby 0.95 Dez 1995Ruby 1.8 Ago 2003Rails 0.8 Dez 2005Ruby 1.9 Dez 2007
  5. 5. Ruby 0.95 Dez 1995Ruby 1.8 Ago 2003Rails 0.8 Dez 2005Ruby 1.9 Dez 2007
  6. 6. Ruby 2.0 24 de Fevereiro de 2013
  7. 7. Compatível com 1.9
  8. 8. Literal Symbol List
  9. 9. > %q[hello world]=> "hello world"> %i[hello world]=> [:hello, :world]
  10. 10. Keyword Arguments
  11. 11. def foo(options = {}) param1 = options[:param1] param2 = options[:param2] return [param1, param2]end> foo param1: "Hello", param2: "World"=> ["Hello", "World"]
  12. 12. def foo(param1: nil, param2: nil) return [param1, param2]end> foo param1: "Hello", param2: "World"=> ["Hello", "World"]
  13. 13. Module Prepend
  14. 14. > [1,2,3].to_s=> "[1, 2, 3]"
  15. 15. module Foo def self.included(base) base.class_eval do alias_method :original_to_s, :to_s def to_s original_to_s + ", Foo" end end endendclass Array include Fooend
  16. 16. > [1,2,3].to_s=> "[1, 2, 3], Foo"> Array.ancestors=> [Array, Foo, Enumerable, Object, Kernel,BasicObject]
  17. 17. module Foo def to_s super + ", Foo" endendclass Array prepend Fooend
  18. 18. > [1,2,3].to_s=> "[1, 2, 3], Foo"> Array.ancestors=> [Foo, Array, Enumerable, Object, Kernel,BasicObject]
  19. 19. Lazy Enumerators
  20. 20. > a = (0..3).map { |i| i }=> [0, 1, 2, 3]
  21. 21. > a = (0..3).lazy.map { |i| i }=> #<Enumerator::Lazy: #<Enumerator::Lazy: 0..3>:map>> a.next=> 0> a.next=> 1> a.next=> 2> a.next=> 3
  22. 22. > a = (0..Float::INFINITY).lazy.map { |i| i }=> #<Enumerator::Lazy: #<Enumerator::Lazy:0..Infinity>:map>> a.next=> 0> a.next=> 1> a.next=> 2> a.next=> 3
  23. 23. Refinements
  24. 24. module Foo def hello "Hello, #{to_s}" endendclass Array include Fooend> [1,2,3].hello=> "Hello, [1, 2, 3]"
  25. 25. module Foo refine Array do def hello "Hello, #{to_s}" end endendusing Foo> [1,2,3].hello=> "Hello, [1, 2, 3]"
  26. 26. module Foo def bah refine Array do [1,2,3].hello def hello end "Hello, #{to_s}" end > bah.hello end NoMethodError: undefinedend method `hello for "Hello, [1, 2,using Foo 3]":String> [1,2,3].hello=> "Hello, [1, 2, 3]"
  27. 27. http://rvm.io
  28. 28. curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled
  29. 29. http://gembundler.com/
  30. 30. BrowserNGINXWorker Linux
  31. 31. BrowserNGINXWorker Linux
  32. 32. BrowserNGINXWorker Ruby Linux
  33. 33. BrowserNGINXWorker Rails Ruby Linux
  34. 34. BrowserNGINXWorker Rails Ruby Linux
  35. 35. Browser Browser Browser Browser NGINXWorker Worker Worker Worker Rails Rails Rails RailsRuby Ruby Ruby Ruby Linux
  36. 36. Browser Browser Browser Browser NGINXWorker Worker Worker Worker Rails Rails Rails RailsRuby Ruby Ruby Ruby Linux
  37. 37. M&SMark & Sweep GC
  38. 38. struct RBasic { VALUE flags; RString flags VALUE klass; klass};
  39. 39. RString RString RString flags flags flags klass klass klass
  40. 40. RString RString RString flags flags flags klass klass klass fork()
  41. 41. RString RString RString flags flags flags klass klass klass fork()
  42. 42. RString RString RString flags flags flags klass klass klass GC.start()RString RString RString flags flags flags klass klass klass
  43. 43. OOBW Out of Band Work
  44. 44. LazyLazy Sweep GC - Ruby 1.9.3
  45. 45. “CoW” Copy on Write
  46. 46. RString RString RString flags flags flags klass klass klass
  47. 47. RString RString RString flags flags flags klass klass klass
  48. 48. RString RString RString flags flags flags klass klass klass
  49. 49. RString RString RString flags flags flags klass klass klass
  50. 50. fork()
  51. 51. GC.start
  52. 52. BitmapBitmap Marking GC - Ruby 2.0
  53. 53. 9 000010018 000010007 00000111
  54. 54. 9 000010018 000010007 00000111
  55. 55. 9 000010018 000010007 00000111
  56. 56. 00000001 2^0 1 User00000010 2^1 2 Moderator00000100 2^2 4 Administrator
  57. 57. 00000001 2^0 1 User00000010 2^1 2 Moderator00000100 2^2 4 Administrator
  58. 58. 00000001 2^0 1 User00000010 2^1 2 Moderator00000100 2^2 4 Administrator
  59. 59. 1 1 1 0 0 0 0 0 0 0 0
  60. 60. 1 1 1 0 0 0 0 0 0 0 0 fork()
  61. 61. fork()
  62. 62. fork()
  63. 63. Browser Browser Browser Browser NGINXWorker Worker Worker Worker Rails Rails Rails RailsRuby Ruby Ruby Ruby Linux
  64. 64. Browser Browser Browser Browser Browser Browser Browser Browser Browser Browser NGINX Worker Worker Worker Worker Worker Worker Worker Worker Worker Worker Rails Rails Rails Rails Rails Rails Rails Rails Rails Rails RubyRuby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Linux
  65. 65. Browser Browser Browser Browser Browser Browser Browser Browser Browser Browser NGINX Worker Worker Worker Worker Worker Worker Worker Worker Worker Worker Rails Rails Rails Rails Rails Rails Rails Rails Rails Rails RubyRuby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Linux
  66. 66. Rails 3.2.12+ Rails 4.0
  67. 67. Thanks! @akitaonrails

×