Ruby 2.17. RVM!
$ rvm get head!
$ rvm install ruby-2.1.0!
$ rvm use ruby-2.1.0!
13. Complex Literals!
< Ruby 2.1
> Complex(2, 3)!
=> (2+3i)!
Ruby 2.1
> (2 + 3i)!
=> (2+3i)!
> (2 + 3i) + Complex(5, 4i)!
=> (3+3i)!
21. def's return value!
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]!
22. def's return value!
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]!
28. Using a Refinement!
class Post!
->using Permalinker!
module Permalinker!
!
refine String do!
def permalinkify!
def initialize(title)!
downcase.split.join("-")!
@title = title!
end!
end!
end!
end!
!
!
def permalink!
@title.permalinkify!
end!
end!
29. Using a Refinement!
class Post!
using Permalinker!
module Permalinker!
!
refine String do!
def permalinkify!
def initialize(title)!
downcase.split.join("-")!
@title = title!
end!
end!
end!
end!
!
!
def permalink!
->@title.permalinkify!
end!
end!
31. Required Keyword Args!
< Ruby 2.1
def permalinkfiy(str, delimiter: "-")!
str.downcase.split.join(delimiter)!
end!
Question: How do we make str
required?!
33. Required Keyword Args!
> permalinkify(delimiter: "-lol-")!
ArgumentError: missing keyword: str!
from (irb):49!
from /usr/local/var/rbenv/
versions/2.1.0/bin/irb:11:in `<main>'!
40. Generational GC!
• split objects into young
and old based on whether
they survive a garbage
collection run.!
• concentrate on freeing up
memory on the young
generation.!
41. Why "Restricted"?!
• still using Mark and Sweep
to garbage collect young/
old generations!
• preserve compatibility with
C extensions!
48. require 'allocation_stats'!
!
class Post!
def initialize(title)!
@title = title!
end!
!
def tags!
%w(ruby programming code).map do |tag|!
tag.upcase!
end!
end!
end!
!
stats = AllocationStats.trace do!
post = Post.new("title")!
post.tags!
end!
!
puts stats.allocations(alias_paths: true).to_text!
55. Learn to build your own concurrent, distributed
web application – The fun & easy way!
http://www.exotpbook.com/!