Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

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

1.251 Aufrufe

Veröffentlicht am

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

  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

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? && date.day <= 7enddrinkups = Date.today..Float::INFINITY .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:https://bugs.ruby-lang.org/projects/ruby-trunk/roadmap#2.0.0https://github.com/ruby/ruby/blob/v2_0_0_rc1/NEWShttps://bugs.ruby-lang.org/projects/ruby-trunk/wiki/RefinementsSpechttp://blog.headius.com/2012/11/refining-ruby.htmlhttp://ruby-doc.org/core-2.0/Enumerator/Lazy.htmlhttp://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/51301http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0http://www.ruby-forum.com/topic/4409612http://www.ruby-forum.com/topic/4408480http://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