Successfully reported this slideshow.

Ruby 2.0: to infinity... and beyond!

5,128 views

Published on

Palestra dada durante a RubyMastersConf 2011, sobre o futuro da linguagem e o que anda na cabeça do Matz.

Published in: Technology
  • Be the first to comment

Ruby 2.0: to infinity... and beyond!

  1. 1. ao infinito... e além! Ruby 2.0
  2. 2. Traits
  3. 3. module Logger def log(message) puts message endendclass ComplexBusiness include Logger # ...endComplexBusiness.ancestors# => [ComplexBusiness, Logger, ...]
  4. 4. module Logger def log(message) puts message endendclass ComplexBusiness mix Logger # ...endComplexBusiness.ancestors# => [ComplexBusiness, Object, ...]
  5. 5. module Extra; endmodule More; endclass ComplexBusiness include Extraendmodule Extra include MoreendComplexBusiness.ancestors# => [ComplexBusiness, Extra, Object, ...]Extra.ancestors# => [Extra, More]
  6. 6. module Logger module EmailNotification def error(message) def error(message) puts "ERROR #{message}" # send mail ... end end def info(message) end puts "INFO #{message}" endend
  7. 7. class ComplexBusiness include Logger include EmailNotificationend
  8. 8. class ComplexBusiness mix Logger mix EmailNotification # exception!end
  9. 9. class ComplexBusiness mix Logger, :error => :log_error mix EmailNotificationend
  10. 10. class ComplexBusiness mix Logger, :error => nil mix EmailNotificationend
  11. 11. Method Combination
  12. 12. class ComplexBusiness def log(message) puts message endend
  13. 13. module Formatter def log(message) original_log("*** #{message} ***") endendclass ComplexBusiness def log(message) puts message endend
  14. 14. module Formatter def log(message) original_log("*** #{message} ***") endendclass ComplexBusiness def log(message) puts message end include Formatterend
  15. 15. module Formatter def log(message) original_log("*** #{message} ***") endend alias_method_chain ?class ComplexBusiness def log(message) puts message end include Formatterend
  16. 16. module Formatter def log(message) original_log("*** #{message} ***") endendclass ComplexBusiness def log(message) puts message end mix Formatterend
  17. 17. module Formatter def log(message) super("*** #{message} ***") endendclass ComplexBusiness def log(message) puts message end mix Formatter, :log => []end
  18. 18. module Formatter def log(message) super("*** #{message} ***") endendclass ComplexBusiness def log(message) puts message end prepend Formatterend
  19. 19. ComplexBusiness.ancestors# => [Formatter, ComplexBusiness, ...]
  20. 20. **kwargs
  21. 21. transfer amount: 100, from: company, to: employee
  22. 22. transfer amount: 100, from: company, to: employee def transfer(hash) value = hash[:amount] source = hash[:from] destination = hash[:to] # do the transfer ... end
  23. 23. transfer amount: 100, from: company, to: employeedef transfer(amount: value, from: source, to: destination) # do the transfer ...end
  24. 24. Refinements
  25. 25. require "rspec"describe RSpecWithRefinements do it "patches objects only inside this block" do "some string".should respond_to(:should_not) 1234.should respond_to(:should_not) endend1234.should # error!
  26. 26. refine Klass {}using Namespaceescopo léxicoherança, class_eval,module_eval, instance_eval
  27. 27. Ruby ISOstandardization
  28. 28. Riteembedding Ruby
  29. 29. Dúvidas? fabio.kung@gmail.comfabio.kung@locaweb.com.br Obrigado!http://twitter.com/fabiokung

×