Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ruby 2.0 at the Ruby drink-up of Sophia, February 2013

Presented at the Ruby Drink-up of Sophia Antipolis on the 5th of February 2013 by Philippe Antras (@_philant_).

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to comment

  • Be the first to like this

Ruby 2.0 at the Ruby drink-up of Sophia, February 2013

  1. 1. Ruby 2.0 bootstrap for discussionPhilippe Antras@_philant_ Riviera.rb
  2. 2. The version number goes up to 2.0 butthe changes are rather small. Smallerthan the ones we made in 1.9. Matz
  3. 3. refinementsexperimentallocalized monkey patchingrefinements are file scopeonly top-level "using" is availableno module scope refinementno refinement inheritance
  4. 4. refinement example module MyModule refine String do def price? self.include? "$" end end end using MyModule p "$13".price?
  5. 5. keyword arguments(named parameters)mandatory argumentsdefault valuesparameter validationlist (with splat operator)readability
  6. 6. def ruby_drinkup(topics, # mandatory where: "the Green King", date: "02/05/13", time: "18:30", announced: false, booked: false) ...endruby_drinkup(["rubinius", "ruby 2.0"])ruby_drinkup(["???"], date: "03/05/13")ruby_drinkup(["rubinius", "ruby 2.0"], reserved: true, announced: false)
  7. 7. lazy enumeratorsbuild an internal block and iterates only onceenumerate infinite or very large datasetsiterate on a file without loading it all map flat_map select reject grep zip take take_while drop drop_while cycle
  8. 8. next drinkup dates ?def first_tuesday?(date) date.tuesday? && <= 7enddrinkups = .lazy .select { |day| first_tuesday?(day) } .take_while { |day| day.year == 2013 } .forceputs drinkups
  9. 9. lines = File.foreach(BIG_FILE) .lazy .select { |line| line.match /ERR/ } .take(10) .to_a
  10. 10. rails
  11. 11. takeaway2.0.0-rc2 delayed yesterdayrefinements, safer, cleaner, but experimentalkeyword argumentslazy enumeratorscompatible with Rails 3.2
  12. 12. so, whats new ?module#prepend declarations of the module overwrite those in the classArray#bsearch { |x| block } elements have to be ordered or nil is returnedEnumerator#size, Range#size#to_h convert Struct and OpenStruct to Hash%i and %I %i{one two three} => [:one, :two, :three]Dtrace support
  13. 13. what changed ?onigmo (new regex engine) positive and negative lookbehind, named captures, backreferences improvedgarbage collector bitmap marking, smaller memory footprintpsych (use libyaml)default encoding now is UTF-8respond_to? returns false for protected methodsiconv has been removed use String#encode instead
  14. 14. referencesfor more details:
  15. 15. wanna give it a try ?thank you