Heroku waza 2013Lessons LearnedPete HudginsTwitter: @phudginsGithub: phudgins
Waza?Art, Technique
I attended•Keynote - Michael Lopp•Unfactoring - Aaron Patterson•Dismantling the Monorail - Jack Lawson•Design Minded Devel...
Ruby 2.0
Yukihiro MatzMatsumoto@yukihiro_matz• Creator of Ruby• Hired by Heroku as ‘ChiefArchitect, Ruby’
Why Ruby?"I hope to see Ruby help every programmer in the world tobe productive, and to enjoy programming, and to be happy."
Ruby 2.0“Happiest release ever"
Why Ruby 2.0?• 1.8.7 will die SOON• ‘100% Compatible’ with Rails 4.0• Available on Heroku NOW• Cool new features
Ruby 2.0 Features• Keyword Arguments• Symbol array literals• UTF-8 by default• Scoped Monkey-Patching
Keyword Arguments• Use for named, optional arguments• No specific order• Descriptive• Easy to remember
Keyword ArgumentsRuby 1.9:def self.find_by_division_id(employer_id, opts={})opts.symbolize_keys!params = opts.reject { |k,...
Keyword ArgumentsWhat if we want:• An arbitrary number of opts?• To have nil as a valid value?• Descriptive Exceptions?
Keyword ArgumentsRuby 1.9:def log(*msgs)opt = msgs.last.is_a?(Hash) ? msgs.pop : {}level = opt.key?(:level) ? opt.delete(:...
Keyword Arguments
Keyword ArgumentsRuby 2.0:def log(msg, level: "ERROR", time: Time.now)puts "#{ time.ctime } [#{ level }] #{ msg }"end
Symbol ArrayLiteralsNeed a quick array of symbols?%i(foo bar) # => [:foo, :bar]
Scoped monkeypatchingMonkey Patching?
monkey patching• Ruby 1.9 uses Open Class• Add methods to existing classes• Replace methods in existing classes• Example: ...
monkey patchingWhat could possibly go wrong?
monkey patchingclass Stringdef to_slug(id)self.truncate(30, separator:  , omission: ).parameterize + "-#{id}"endend
monkey patchingclass Stringdef to_slug(id)"#{id}-" + self.truncate(30,separator:  ,omission: ).parameterizeendend
monkey patchingGlobal modification is BAD
Scoped monkeypatchingUse Refinements!
Scoped monkeypatchingmodule GemNamerefine Stringdef to_slug(id). . .endendend
Ruby 2.0Questions?
Pete Heroku Waza 2013 Ruby 2.0
Upcoming SlideShare
Loading in …5
×

Pete Heroku Waza 2013 Ruby 2.0

532 views

Published on

Lessons learned from Heroku Waza Conference 2013. Particularly Matz's talk on Ruby 2.0

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
532
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Japanese word for Art and Technique. As developers and engineers, we should think about our art and our craft.
  • Focus on Talk Ruby 2.0
  • Created Ruby on February 24, 1993
  • Why did Matz create Ruby? Other languages work ok Matz wanted something that was '...more powerful than Perl, and more object-oriented than Python…’ Primarily:
  • Primarily: ‘ For me, the purpose of life is, at least partly, to have joy. Programmers often feel joy when they can concentrate on the creative side of programming, so Ruby is designed to make programmers happy.’
  • Ruby 2.0 was released on it’s 20 th birthday. Matz considered the release schedule as ‘Anniversary Driven Development’ or ‘ADD’
  • Why move to Ruby 2.0? Rails 4.0 ‘prefers’ Ruby 2.0
  • We can do keyword arguments in 1.9, with an opts hash.
  • We clearly have an issue here..
  • We can do keyword arguments in 2.0
  • ActiveSupport example: 20.years.ago
  • One developer adds to_slug to String class
  • Another developer adds to_slug to String class
  • If you call to_slug without using the module, an error is thrown.
  • Pete Heroku Waza 2013 Ruby 2.0

    1. 1. Heroku waza 2013Lessons LearnedPete HudginsTwitter: @phudginsGithub: phudgins
    2. 2. Waza?Art, Technique
    3. 3. I attended•Keynote - Michael Lopp•Unfactoring - Aaron Patterson•Dismantling the Monorail - Jack Lawson•Design Minded Development - Austin Bales•Instrumenting Twelve-Factor Apps - Joseph Ruscio•Caring for your Baby Ecosystem - Jacob Kaplan-Moss•Ruby 2.0 - Yukihiro Matz Matsumoto•Everything is a Remix - Kirby Ferguson
    4. 4. Ruby 2.0
    5. 5. Yukihiro MatzMatsumoto@yukihiro_matz• Creator of Ruby• Hired by Heroku as ‘ChiefArchitect, Ruby’
    6. 6. Why Ruby?"I hope to see Ruby help every programmer in the world tobe productive, and to enjoy programming, and to be happy."
    7. 7. Ruby 2.0“Happiest release ever"
    8. 8. Why Ruby 2.0?• 1.8.7 will die SOON• ‘100% Compatible’ with Rails 4.0• Available on Heroku NOW• Cool new features
    9. 9. Ruby 2.0 Features• Keyword Arguments• Symbol array literals• UTF-8 by default• Scoped Monkey-Patching
    10. 10. Keyword Arguments• Use for named, optional arguments• No specific order• Descriptive• Easy to remember
    11. 11. Keyword ArgumentsRuby 1.9:def self.find_by_division_id(employer_id, opts={})opts.symbolize_keys!params = opts.reject { |k,v| v.blank? }. . .end
    12. 12. Keyword ArgumentsWhat if we want:• An arbitrary number of opts?• To have nil as a valid value?• Descriptive Exceptions?
    13. 13. Keyword ArgumentsRuby 1.9:def log(*msgs)opt = msgs.last.is_a?(Hash) ? msgs.pop : {}level = opt.key?(:level) ? opt.delete(:level) : "ERROR"time = opt.key?(:time) ? opt.delete(:time) : Time.nowraise "unknown key: #{opt.keys.first}" if !opt.empty?msgs.map do |msg|puts "#{ time.ctime } [#{ level }] #{ msg }"endend
    14. 14. Keyword Arguments
    15. 15. Keyword ArgumentsRuby 2.0:def log(msg, level: "ERROR", time: Time.now)puts "#{ time.ctime } [#{ level }] #{ msg }"end
    16. 16. Symbol ArrayLiteralsNeed a quick array of symbols?%i(foo bar) # => [:foo, :bar]
    17. 17. Scoped monkeypatchingMonkey Patching?
    18. 18. monkey patching• Ruby 1.9 uses Open Class• Add methods to existing classes• Replace methods in existing classes• Example: ActiveSupport
    19. 19. monkey patchingWhat could possibly go wrong?
    20. 20. monkey patchingclass Stringdef to_slug(id)self.truncate(30, separator: , omission: ).parameterize + "-#{id}"endend
    21. 21. monkey patchingclass Stringdef to_slug(id)"#{id}-" + self.truncate(30,separator: ,omission: ).parameterizeendend
    22. 22. monkey patchingGlobal modification is BAD
    23. 23. Scoped monkeypatchingUse Refinements!
    24. 24. Scoped monkeypatchingmodule GemNamerefine Stringdef to_slug(id). . .endendend
    25. 25. Ruby 2.0Questions?

    ×