module FloatDivision
refine Fixnum do
def /(other); self.to_f / other; end
end
end
class MathFun
using FloatDivision
def self.ratio(a, b)
a / b
end
end
p MathFun.ratio(6, 8)
THE OLD IDEA (no longer works)
Slide 7
Slide 7 text
module FloatDivision
refine Fixnum do
def /(other); self.to_f / other; end
end
end
class MathFun
using FloatDivision
def self.ratio(a, b)
a / b
end
end
p MathFun.ratio(6, 8)
Slide 8
Slide 8 text
module FloatDivision
refine Fixnum do
def /(other); self.to_f / other; end
end
end
using FloatDivision
class MathFun
def self.ratio(a, b)
a / b
end
end
p MathFun.ratio(6, 8)
Main context is OK
Slide 9
Slide 9 text
Keyword Arguments
definitely a: “pretty”, good:
“addition”, to: “the language”
infinite_range = (0..Float::INFINITY)
e = infinite_range.lazy.select { |num| num % 74 == 0 }
puts e.next
puts e.next
puts e.next
Slide 16
Slide 16 text
Module#prepend
Slide 17
Slide 17 text
module Bar
def my_method
"inside the module"
end
end
class Foo
include Bar
def my_method
"inside the class"
super
end
end
x = Foo.new
p x.my_method
1
2
Slide 18
Slide 18 text
module Bar
def my_method
"inside the module"
super
end
end
class Foo
prepend Bar
def my_method
"inside the class"
end
end
x = Foo.new
p x.my_method
1
2
Slide 19
Slide 19 text
INCLUDE PREPEND
Foo class
Bar module
x object
NEITHER
Foo class
x object
Object class
Object class
Foo class
Bar module
x object
Object class
Slide 20
Slide 20 text
DETAILS
Slide 21
Slide 21 text
ABI Breakage
Changes to the Application Binary
Interface
Slide 22
Slide 22 text
Regex engine changed
From Oniguruma to Onigmo
Slide 23
Slide 23 text
%{this\r\nis\n\ncool\vhello!}.gsub(/\R/, '')
Slide 24
Slide 24 text
RubyGems 2.0
Lots of refactoring, initial support
for stdlib gemification, gem search
is now remote, arbitrary
metadata support & more.
Slide 25
Slide 25 text
RDoc 4.0
Adds Markdown support & ri can
now show pages (e.g. READMEs
with ri rdoc:README)
Slide 26
Slide 26 text
%i and %I
To form arrays of symbols, like %w
does for words and arrays
UTF-8 is default
source encoding
No more # encoding: utf-8 (if you
don’t want)
Slide 29
Slide 29 text
Bitmap garbage
collector
Faster, more efficient
Slide 30
Slide 30 text
CSV.load and
CSV.dump gone
Not considered such a good idea
in light of the early 2013 YAML
vulnerabilities
Slide 31
Slide 31 text
String#chars, #lines,
#codepoints, etc.
Now return arrays rather than
enumerators.
Use #each_char, #each_line, etc.
instead if you need enumerators.
Slide 32
Slide 32 text
TracePoint
A more object oriented alternative
to set_trace_func
Slide 33
Slide 33 text
tracer = lambda do |event, file, line, id, binding, klass|
to_display = [event, File.basename(file), line, klass, id]
puts "%10s in %s at line %-2d %s:%s" % to_display
end
set_trace_func tracer
# .. normal code here ..
Slide 34
Slide 34 text
tracer = TracePoint.new do |tp|
to_display = [tp.event, File.basename(tp.path), tp.lineno,
tp.defined_class, tp.method_id]
puts "%10s in %s at line %-2d %s:%s" % to_display
end
tracer.enable
# .. normal code here ..
Slide 35
Slide 35 text
respond_to?
respond_to? against a protected
method now returns false
Slide 36
Slide 36 text
Method transplants
with define_method
Now accepts UnboundMethods
Slide 37
Slide 37 text
module M
def foo; "foo"; end
end
define_method :foo, M.instance_method(:foo)
p foo
Slide 38
Slide 38 text
Array#bsearch
Range#bsearch
Binary search for monotonic
collections