Download - Wild & Weird Ideas: An Overview of Ruby 1.9

Transcript
Page 1: Wild & Weird Ideas: An Overview of Ruby 1.9

Wild &Weird Ideas

An overview of Ruby 1.9LRUG 10th december 2007

Page 2: Wild & Weird Ideas: An Overview of Ruby 1.9

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/

Page 3: Wild & Weird Ideas: An Overview of Ruby 1.9

When is it coming out?

Christmas 2007

Page 4: Wild & Weird Ideas: An Overview of Ruby 1.9

The Biggest Change

becomes

Page 5: Wild & Weird Ideas: An Overview of Ruby 1.9

The Biggest Change

... but let’s not complainours isn’t much better!

Page 6: Wild & Weird Ideas: An Overview of Ruby 1.9

The Real Biggest Change

YARV

Page 7: Wild & Weird Ideas: An Overview of Ruby 1.9

YARV3 Things It Means To Us

1. New developer

• not matz-bound

2. Better Performance

• in places

3. Native threads

• vs. green threads

Page 8: Wild & Weird Ideas: An Overview of Ruby 1.9

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

Page 9: Wild & Weird Ideas: An Overview of Ruby 1.9

Other Changes

a lot

Page 10: Wild & Weird Ideas: An Overview of Ruby 1.9

New Syntax

Page 11: Wild & Weird Ideas: An Overview of Ruby 1.9

=> #<Proc:0x48adf0@(irb):34 (lambda)>irb> c.call(2, 'hello')hellohello=> 2

irb> c = -> (a, b) {a.times{puts b}}

Page 12: Wild & Weird Ideas: An Overview of Ruby 1.9

=> #<Proc:0x52f17a@(irb):50 (lambda)>irb> c.call(1)muz=> 1

irb> c = ->(a, b = ‘muz’) doirb* a.times{puts b}irb> end

Page 13: Wild & Weird Ideas: An Overview of Ruby 1.9

=> #<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

Page 14: Wild & Weird Ideas: An Overview of Ruby 1.9

=> 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

Page 15: Wild & Weird Ideas: An Overview of Ruby 1.9

irb> c.(2, 'hello')hellohello=> 2

irb> c = -> (a, b) {a.times{puts b}}=> #<Proc:0x48adf0@(irb):34 (lambda)>

Page 16: Wild & Weird Ideas: An Overview of Ruby 1.9

=> [1,2,3,4,5,6]

irb> num = [1,2,3]irb> bers = [4,5,6]irb> numbers = [*num, *bers]

Page 17: Wild & Weird Ideas: An Overview of Ruby 1.9

Changes to the Standard

Library

Page 18: Wild & Weird Ideas: An Overview of Ruby 1.9

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

Page 19: Wild & Weird Ideas: An Overview of Ruby 1.9

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

Page 20: Wild & Weird Ideas: An Overview of Ruby 1.9

Symbol

• Symbol#to_proc

• [”matz”, “koichi”].map(&:upcase) #=> [“MATZ”, “KOICHI”]

• Treated more like Strings

• #encoding, #empty?, #upcase, #[], #match, etc...

• #===

Page 21: Wild & Weird Ideas: An Overview of Ruby 1.9

IO

• Non blocking IO

• Limit input in read/get methods

• Oddness: doesn’t appear to be encoding aware

Page 22: Wild & Weird Ideas: An Overview of Ruby 1.9

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

Page 23: Wild & Weird Ideas: An Overview of Ruby 1.9

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/

Page 24: Wild & Weird Ideas: An Overview of Ruby 1.9

How do I get it?

• Wait till Christmas?

• http://svn.ruby-lang.org/repos/ruby/trunk

• Tiger users - upgrade your bison

• Windows binaries available

Page 25: Wild & Weird Ideas: An Overview of Ruby 1.9

~fin~