Ruby 2.1 Overview

Ruby 2.1 Overview

(For HoustonRB)

3b5cb0411cbd1012acab1b60f7ce3606?s=128

Jesse Wolgamott

January 15, 2014
Tweet

Transcript

  1. @jwo Ruby 2.1

  2. @jwo `def` returns a method

  3. @jwo module Foo! def public_method! end! ! def some_other_method! end!

    ! private :some_other_method! ! private! def a_private_method! end! end! ! Foo.private_instance_methods! => [:some_other_method, :a_private_method]
  4. @jwo module Foo! def public_method! end! ! private def some_other_method!

    end! ! private def a_private_method! end! end! ! Foo.private_instance_methods! => [:some_other_method, :a_private_method]
  5. @jwo Refinements Launched and the world did not end.

  6. @jwo module Permalinker! refine String do! def permalinkify! downcase.split.join("-")! end!

    end! end
  7. @jwo class Post! using Permalinker! ! def initialize(title)! @title =

    title! end! ! def permalink! @title.permalinkify! end! end
  8. @jwo "Refinements are not globally scoped".permalinkify! ! ! ! NoMethodError:

    undefined method `permalinkify' for "Refinements are not globally scoped":String
  9. @jwo Restricted Keyword Args

  10. @jwo def order_tacos(type: 5, how_many: 'queso')! puts "Ordering #{how_many} #{type}"!

    end! ! order_tacos type: "fajita_queso", how_many: 5 in Ruby 2.0, you HAD to specify a default for type and how_many
  11. @jwo def order_tacos(type:, how_many:)! puts "Ordering #{how_many} #{type}"! end! !

    order_tacos type: "fajita_queso", how_many: 5! order_tacos type: “fajita_queso"! ! => ArgumentError: missing keyword: how_many NO LONGER
  12. @jwo Restricted Generational Garbage Collector (RGENGC)

  13. @jwo ummm wat

  14. @jwo Ruby 1.8: Mark and Sweep http://tmm1.net/ruby21-rgengc/

  15. @jwo Ruby 1.9.3 “Lazy Sweep” http://tmm1.net/ruby21-rgengc/

  16. @jwo Ruby 2.0 bitmaps for copy-on-write safety http://tmm1.net/ruby21-rgengc/

  17. @jwo Ruby 2.1: OldGen and minor marking http://tmm1.net/ruby21-rgengc/

  18. @jwo Some Graphs!

  19. @jwo Some Little Stuff

  20. @jwo 27r # => Rational(27/1)! 1/2r # => Rational(1/2)! 12+33i

    # => Complex(12,33) Decimal Literal Syntax
  21. @jwo 3.times{puts'blah'.object_id}! # => 70287241728160! # => 70287241728080! # =>

    70287241728020! ! 3.times{puts'blah'f.object_id}! # => 70287241709760 ! # => 70287241709760! # => 70287241709760 Frozen String Literal (Same)
  22. @jwo $ stackprof data/stackprof-cpu-4120-1384979644.dump --text --limit 4 ================================== Mode: cpu(1000)

    Samples: 9145 (1.25% miss rate) GC: 448 (4.90%) ================================== TOTAL (pct) SAMPLES (pct) FRAME 236 (2.6%) 231 (2.5%) String#blank? 546 (6.0%) 216 (2.4%) ActiveRecord::ConnectionAdapters::Mysql2Adapter#select 212 (2.3%) 199 (2.2%) Mysql2::Client#query_with_timing ! $ stackprof data/stackprof-cpu-4120-1384979644.dump --method 'String#blank?' String#blank? (lib/active_support/core_ext/object/blank.rb:80) samples: 231 self (2.5%) / 236 total (2.6%) callers: 112 ( 47.5%) Object#present? code: | 80 | def blank? 187 (2.0%) / 187 (2.0%) | 81 | self !~ /[^[:space:]]/ Profiling Tools (rb_profile_frames)
  23. @jwo Install today!