Ruby 2.1 Overview

Ruby 2.1 Overview

(For HoustonRB)

3b5cb0411cbd1012acab1b60f7ce3606?s=128

Jesse Wolgamott

January 15, 2014
Tweet

Transcript

  1. 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]
  2. 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]
  3. 7.

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

    title! end! ! def permalink! @title.permalinkify! end! end
  4. 8.

    @jwo "Refinements are not globally scoped".permalinkify! ! ! ! NoMethodError:

    undefined method `permalinkify' for "Refinements are not globally scoped":String
  5. 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
  6. 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
  7. 20.

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

    # => Complex(12,33) Decimal Literal Syntax
  8. 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)
  9. 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)