Successfully reported this slideshow.

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

0

Share

Upcoming SlideShare
Formaldehye2  job program
Formaldehye2 job program
Loading in …3
×
1 of 15
1 of 15

More Related Content

Related Audiobooks

Free with a 30 day trial from Scribd

See all

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

  1. 1. Ruby 2.0 bootstrap for discussion Philippe Antras @_philant_ Riviera.rb
  2. 2. The version number goes up to 2.0 but the changes are rather small. Smaller than the ones we made in 1.9. Matz
  3. 3. refinements experimental localized monkey patching refinements are file scope only top-level "using" is available no module scope refinement no 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 arguments default values parameter validation list (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) ... end ruby_drinkup(["rubinius", "ruby 2.0"]) ruby_drinkup(["???"], date: "03/05/13") ruby_drinkup(["rubinius", "ruby 2.0"], reserved: true, announced: false)
  7. 7. lazy enumerators build an internal block and iterates only once enumerate infinite or very large datasets iterate 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? && date.day <= 7 end drinkups = Date.today..Float::INFINITY .lazy .select { |day| first_tuesday?(day) } .take_while { |day| day.year == 2013 } .force puts drinkups
  9. 9. lines = File.foreach(BIG_FILE) .lazy .select { |line| line.match /ERR/ } .take(10) .to_a
  10. 10. rails
  11. 11. takeaway 2.0.0-rc2 delayed yesterday refinements, safer, cleaner, but experimental keyword arguments lazy enumerators compatible with Rails 3.2
  12. 12. so, what's new ? module#prepend declarations of the module overwrite those in the class Array#bsearch { |x| block } elements have to be ordered or nil is returned Enumerator#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 improved garbage collector bitmap marking, smaller memory footprint psych (use libyaml) default encoding now is UTF-8 respond_to? returns false for protected methods iconv has been removed use String#encode instead
  14. 14. references for more details: https://bugs.ruby-lang.org/projects/ruby-trunk/roadmap#2.0.0 https://github.com/ruby/ruby/blob/v2_0_0_rc1/NEWS https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/RefinementsSpec http://blog.headius.com/2012/11/refining-ruby.html http://ruby-doc.org/core-2.0/Enumerator/Lazy.html http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/51301 http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about- garbage-collection-in-ruby-2-0 http://www.ruby-forum.com/topic/4409612 http://www.ruby-forum.com/topic/4408480 http://globaldev.co.uk/2012/11/ruby-2-0-0-preview-features/ https://speakerdeck.com/a_matsuda/ruby-2-dot-0-on-rails
  15. 15. wanna give it a try ? thank you

×