View
14.023
Download
0
Category
Preview:
DESCRIPTION
A presentation I gave at the London Ruby User Group (LRUG) in December 2007 about the changes in the ruby programming language in the soon to be released 1.9 version. Note that Ruby 1.9 was still in development at the time I wrote this talk, so it's possible the stuff I say in it is completely inaccurate with respect to any currently released version of Ruby 1.9.
Citation preview
Wild &Weird Ideas
An overview of Ruby 1.9LRUG 10th december 2007
What is it?
• The last odd-numbered release before Ruby 2.0
• “Wild & Weird Ideas”- Matz, RubyConf 2005
• More open development• http://www.rcrchive.net/
When is it coming out?
Christmas 2007
The Biggest Change
becomes
The Biggest Change
... but let’s not complainours isn’t much better!
The Real Biggest Change
YARV
YARV3 Things It Means To Us
1. New developer
• not matz-bound
2. Better Performance
• in places
3. Native threads
• vs. green threads
New literal hash syntax Block local variables
Block arguments are always local
New syntax for lambdas
.() and calling Procs without #call/#[]
Block arguments
News semantics for block arguments
Method used for splat arguments: #to_splat
Multiple splats allowed
Mandatory arguments after optional arguments allowed
?c semantics
Arguments to #[]
printf-style formatted strings (%)
Newlines allowed before ternary colondefined? and local variables
BasicObject
#instance_exec
send doesn't always call private methods anymore
Kernel#require
Object#=~
Object#tap
Kernel#instance_variable_defined?
Kernel#define_singleton_method
Kernel#singleton_methods, Kernel#methods
Module#*_instance_methods
Module#const_defined?, #const_get
Module#class_variable_defined?
#class_variable_{set,get}
Module#attr is an alias of attr_reader
Class of singleton classes
Class variables are not inherited
#module_exec
Extra subclassing check when binding UnboundMethods
Binding#eval
Proc#yield
Arity of blocks without arguments
Passing blocks to #[]
proc is now a synonym of Proc.new
Proc#lambda?
NameError
Equality of exceptions
SystemStackError
Removed Exception#to_str
Enumerable#cycle
Enumerable#each_with_index
Enumerable#first(n)
Enumerable#group_by
Enumerable#find_index
Enumerable#take
Enumerable#drop
Enumerator#each
Enumerable methods called without a block
Enumerable#inject (#reduce) without a block
Enumerable#count
Enumerable#reduce
Enumerator#with_index
Enumerable#min_by, #max_by
Enumerable#zip
Regexp#match, String#match
Enumerable#minmax, #minmax_by
Enumerator#rewind
Fiber: coroutines/micro-threads Array#nitemsArray#[m,n] = nil places nil in the array
Block argument to Array#index, Array#rindex
Array#combination
Array#permutation
Array#productArray#pop, Array#shift
Array#to_s is equivalent to Array#inspect
Array.try_convert
Hash#to_s is equivalent to Hash#inspect
Hash#_compare_by_identity, #compare_by_identity?
Semantics for Hash#each and Hash#each_pair
Hash#select
Hash.try_convert
Integer(nil) raises TypeError
Integer#odd?, #even?
Integer#pred
Method#receiver
Method#name
Method#owner
Numeric#upto, #downto, #times, #step
Numeric#scalar?, Complex#scalar?
Numeric#div
Numeric#fdiv
Range#cover?
Range#include?
Range#min, Range#max
Regexp#=== matches symbols
Regexp.try_convert
String no longer an Enumerable
String has encoding-awareness
String#clear
"One-char-wide" semantics for String#[] and String#[]=
String#each_char
String#ord
String#partition, #rpartition
String#lines
String#bytes
String#encoding
String#force_encoding
String#start_with?, #end_with?
String#unpack with a block
String#hash
String#upto
String.try_convert
Zero-length symbols allowed
Struct#inspect
Symbol#=== matches strings
Symbol#intern
Symbol#encoding
Symbol methods similar to those in String
Math#log and Math#log2
#to_path in File.<blah>
Dir.[], Dir.glob
Dir.exist?
New File and Dir operations
Non-blocking IO
IO#getc
IO & StringIO #getbyte, #readbyte
Kernel#open
IO#initialize now accepts an IO argument
StringIO#readpartial
IO#lines
IO#bytes
IO.try_convert
Limit input
IO#ungetc, StringIO#ungetc
New format in Time#to_s
Timezone information preserved on Marshal.dump/load
Process.setrlimit
Process.daemon
Process.exec
Symbols: restriction on literal symbols
$SAFE and bound methods
GC.stress, GC.stress=
Method#hash, Proc#hash
__method__ and __callee__
Symbol#to_proc
Deprecated: VERSION and friends
Deprecated: StringScanner
Deprecated: Kernel.to_a
Deprecated: Kernel#getc
Deprecated: Object#type
Deprecated: File.exists? Deprecated: Hash#index
Deprecated: ENV.index
Deprecated: Symbol#to_int
Deprecated: Removed Array and Hash #indices, #indexes
Other Changes
Other Changes
a lot
New Syntax
=> #<Proc:0x48adf0@(irb):34 (lambda)>irb> c.call(2, 'hello')hellohello=> 2
irb> c = -> (a, b) {a.times{puts b}}
=> #<Proc:0x52f17a@(irb):50 (lambda)>irb> c.call(1)muz=> 1
irb> c = ->(a, b = ‘muz’) doirb* a.times{puts b}irb> end
=> #<Proc:0x65cd68@(irb):36 (lambda)>irb> c.call(2, 'hello'){|b| puts b*2}hellohellohellohello=> 2
irb> c = ->(a, b, &c) doirb* a.times{c.call(b)}irb> end
=> nilirb> lolmatz(‘RUBY’,’LANGUJ’)=> “IN YR RUBY SPESIFYIN YR LANGUJ”
irb> def lolmatz(n1, v=‘SPESIFY’, n2)irb> “IN YR #{n1} #{v}IN YR #{n2}”irb> end
irb> c.(2, 'hello')hellohello=> 2
irb> c = -> (a, b) {a.times{puts b}}=> #<Proc:0x48adf0@(irb):34 (lambda)>
=> [1,2,3,4,5,6]
irb> num = [1,2,3]irb> bers = [4,5,6]irb> numbers = [*num, *bers]
Changes to the Standard
Library
String
• Encoding aware
• methods are char, not byte, based now
• open(‘blah.txt’, ‘r:utf-8’)
• # -*- coding: utf-8 -*-
• Bye Bye: $KCODE and jcode
• No longer an Enumerable
Enumerable
• Enumerable::Enumerator part of core
• Enumerable methods without a block
• [1,2,3].map.with_index {|item, idx| ...}
• #inject without block
• [1,2,3].inject(:+) #=> 6
Symbol
• Symbol#to_proc
• [”matz”, “koichi”].map(&:upcase) #=> [“MATZ”, “KOICHI”]
• Treated more like Strings
• #encoding, #empty?, #upcase, #[], #match, etc...
• #===
IO
• Non blocking IO
• Limit input in read/get methods
• Oddness: doesn’t appear to be encoding aware
Misc.
• BasicObject at top of class hierarchy
• Class variables (@@woo) not inherited
• proc is now Proc.new instead of lambda
• Proc#yield a method for yield keyword
• send shouldn’t invoke private methods
The Ruby Ecosystem• Rubygems
• 0.9.5 is ruby 1.9 compatible
• Rake
• Rails
• ticket #1689 says Rails 2.1
• mongrel
• http://www.moriq.com/ruby/1.9/log/
How do I get it?
• Wait till Christmas?
• http://svn.ruby-lang.org/repos/ruby/trunk
• Tiger users - upgrade your bison
• Windows binaries available
~fin~
• http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9
• http://www.atdot.net/yarv/rc2006_sasada_yarv_on_rails.pdf
• http://learnruby.com/ruby-1.9.html
• http://www.rubyinside.com/so-heres-the-new-ruby-logo-639.html
• http://www.ruby-lang.org/en/community/ruby-core/
• http://www.rubyist.net/~matz/slides/
• http://blog.grayproductions.net/categories/the_ruby_vm_interview
Recommended