Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby 2.1 Overview

Ruby 2.1 Overview

(For HoustonRB)

Jesse Wolgamott

January 15, 2014
Tweet

More Decks by Jesse Wolgamott

Other Decks in Technology

Transcript

  1. @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. @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. @jwo class Post! using Permalinker! ! def initialize(title)! @title =

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

    undefined method `permalinkify' for "Refinements are not globally scoped":String
  5. @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. @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. @jwo 27r # => Rational(27/1)! 1/2r # => Rational(1/2)! 12+33i

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