Professional Documents
Culture Documents
Ruby 1.9
Bruce Williams
Thanks for having me
out to Boston.
Language Geek
self ocaml
ruby perl haskell
erlang python
basque german
smalltalk
objc java russian
eiffel awk
Rubyist
:-) 2001...2005
:-) + $ 2005..2008
Open Source
Developer
RTeX, TuneUp, keyword_search, numerous Rails
plugins
A bunch of URLs
http://codefluency.com
http://github.com/bruce
http://fiveruns.com
http://twitter.com/wbruce
and 1.9?
YARV
1.9 is just like 1.7.
Except completely
different.
Stable
Releases (dev)
(dev)
1.7
1.9
(dev) ... 2.0
1.5 1.6.1 1.6.3 1.6.5 1.8.1 1.8.4
1.6.0 1.6.2 1.6.4 1.6.7 1.6.8 1.8.0 1.8.2 1.8.3 1.8.5 1.8.6 1.8.7 1.9.1
...
1.9
Not strictly backwards
compatible to 1.8.
Better performance
characteristics.
More bugs (it’s new!)
Many new syntax and
language features.
1.9
Not strictly backwards
compatible to 1.8.
Better performance
Out of scope.
characteristics.
(I’m
More not
bugspsychic)
(it’s new!)
Installing
1.9.0:
http://www.ruby-lang.org/en/downloads/
From Subversion:
$ svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby1.9
$ cd ruby1.9
$ autoconf
$ ./configure --program-suffix=1.9
$ make && sudo make install
Comparison App
$ git clone git://github.com/bruce/compare-1-9.git
$ cd compare-1-9
$ rake db:migrate
$ ruby script/server (use ruby 1.8!)
Standard Library Changes
</obligatory-testing-related-slide>
Risk: Text Processing
Relying on $KCODE, String#[], or String
internals. Parsers especially at risk.
"["ﻛﻠﻤﺎت0]
"["ﻛﻠﻤﺎت0]
# => 217 # => ""ك
"ruby".unpack('U*') ""ﻛﻠﻤﺎت.unpack('U*')
# => [114, 117, 98, 121] # => [1603, 1604, 1605, 1575, 1578]
Risk: Block Var Scope
Modifying variables outside the scope of a
block with a block argument. “Clever”
block tricks.
d = 2 d = 2
-> { d = 1 }.() ->(;d) { d = 1 }.()
d d
# => 1 # => 2
Help!
New Features
XL
Multilingualization
(m17n)
# encoding: utf-8
Named Groups
"His name is Joe".match(/name is (?<name>\S+)/)[:name]
# => "Joe"
Multilingualization
Read a file with File.read
File.read("input.txt").encoding
# => #<Encoding:UTF-8>
[1,2,3,4].reduce(&:+)
# => 10
Enumerable
New Enumerable methods take, group_by, drop, min_by, max_by,
count, and others.
Take Drop
array = [1, 2, 3, 4, 5] array = [1, 2, 3, 4, 5]
array.take(3) array.drop(3)
# => [1, 2, 3] # => [4, 5]
array array
# => [1, 2, 3, 4, 5] # => [1, 2, 3, 4, 5]
Hash Changes
Insertion Order
conferences = {
lsrc: 'Austin',
scotland_on_rails: 'Edinburgh'
}
conferences[:rubyconf] = 'Orlando'
conferences.each do |name, city|
p "#{name} is in #{city}"
end
# "lsrc is in Austin"
# "scotland_on_rails is in Edinburgh"
# "rubyconf is in Orlando"
conferences.delete(:scotland_on_rails)
conferences[:scotland_on_rails] = 'Edinburgh'
conferences.each do |name, city|
p "#{name} is in #{city}"
end
# "lsrc is in Austin"
# "rubyconf is in Orlando"
# "scotland_on_rails is in Edinburgh"
Object
Tap
thing = Thing.new.tap do |thing|
thing.something = 1
thing.something_else = 2
end
New Hash Literal
Symbol shortcut
{foo: 1, bar: 2}
# => {:foo=>1, :bar=>2}
Revactor
NeverBlock
http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html
http://www.davidflanagan.com/blog/2007_08.html
InfoQ, others...
Questions?
Thank You.
bruce@codefluency.com
http://twitter.com/wbruce