Slide 1

Slide 1 text

@jwo Ruby 2.1

Slide 2

Slide 2 text

@jwo `def` returns a method

Slide 3

Slide 3 text

@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]

Slide 4

Slide 4 text

@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]

Slide 5

Slide 5 text

@jwo Refinements Launched and the world did not end.

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

@jwo "Refinements are not globally scoped".permalinkify! ! ! ! NoMethodError: undefined method `permalinkify' for "Refinements are not globally scoped":String

Slide 9

Slide 9 text

@jwo Restricted Keyword Args

Slide 10

Slide 10 text

@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

Slide 11

Slide 11 text

@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

Slide 12

Slide 12 text

@jwo Restricted Generational Garbage Collector (RGENGC)

Slide 13

Slide 13 text

@jwo ummm wat

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

@jwo Some Graphs!

Slide 19

Slide 19 text

@jwo Some Little Stuff

Slide 20

Slide 20 text

@jwo 27r # => Rational(27/1)! 1/2r # => Rational(1/2)! 12+33i # => Complex(12,33) Decimal Literal Syntax

Slide 21

Slide 21 text

@jwo 3.times{puts'blah'.object_id}! # => 70287241728160! # => 70287241728080! # => 70287241728020! ! 3.times{puts'blah'f.object_id}! # => 70287241709760 ! # => 70287241709760! # => 70287241709760 Frozen String Literal (Same)

Slide 22

Slide 22 text

@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)

Slide 23

Slide 23 text

@jwo Install today!