Ruby 1.9: What to Expect by Sam Ruby @ OSCON 2008 Slide Deck AdaptedS6/S9 (Single-Web Page) Version

G

Gerald Bauer

Hello,

I've created a S6/S9 version of Sam Ruby's OSCON 2008 slide deck
titled "Ruby 1.9: What to Expect (What's Changed? What's New?)" that
offers a single-web page version that in addition to offering a
full-screen slide show is easy-to-print for offline reading. (S6/S9
Tip: Use the t-key to toggle between outline and slide show view.)

Topics covered in Sam Ruby's slide show include:

== What's Changed?

* Single Character Strings
* String Index
* {"a","b"} No Longer Supported
* Array.to_s Now Contains Punctuation
* Colon No Longer Valid In When Statements
* Block Variables Now Shadow Local Variables
* Hash.index Deprecated
* Fixnum.to_sym Now Gone
* Hash Keys Now Unordered
* Stricter Unicode Regular Expressions
* tr and Regexp Now Understand Unicode
* pack and unpack
* BasicObject More Brutal Than BlankSlate
* Delegation Changes
* Use of $KCODE Produces Warnings
* instance_methods Now an Array of Symbols
* Source File Encoding

== What's New?

* Alternate Syntax for Symbol as Hash Keys
* Block Local Variables
* Inject Methods
* to_enum
* No block? Enum!
* Lambda Shorthand
* Complex Numbers
* Decimal Is Still Not The Default
* Regex "Properties"
* Splat in Middle
* Fibers
* Break Values
* "Nested" Methods


More @ http://slideshow.rubyforge.org/ruby19.html

Cheers.
 
I

Iñaki Baz Castillo

El Martes, 12 de Agosto de 2008, Gerald Bauer escribi=F3:
* Block Variables Now Shadow Local Variables

What does it mean? For example, in Ruby 1.8 and 1.9 the following code retu=
rns=20
the same:

=2D---------
kk=3D123;
puts "KK out of block =3D #{kk}";
1.upto(3) { puts "KK in block =3D #{kk}"; kk=3D999 };
puts "KK out of block =3D #{kk}"
=2D---------

KK out of block =3D 123
KK in block =3D 123
KK in block =3D 999
KK in block =3D 999
KK out of block =3D 999




=2D-=20
I=F1aki Baz Castillo
 
J

Jeremy Kemper

El Martes, 12 de Agosto de 2008, Gerald Bauer escribi=F3:

What does it mean? For example, in Ruby 1.8 and 1.9 the following code re= turns
the same:

----------
kk=3D123;
puts "KK out of block =3D #{kk}";
1.upto(3) { puts "KK in block =3D #{kk}"; kk=3D999 };
puts "KK out of block =3D #{kk}"
----------

KK out of block =3D 123
KK in block =3D 123
KK in block =3D 999
KK in block =3D 999
KK out of block =3D 999

$ irb-1.8
a =3D 1 =3D> 1
[2].each { |a| } =3D> [2]
a
=3D> 2

$ irb-1.9
a =3D 1 =3D> 1
[2].each { |a| } =3D> [2]
a
=3D> 1

So the block arg 'a' no longer clobbers the local var 'a'.

jeremy
 
I

Iñaki Baz Castillo

El Martes, 12 de Agosto de 2008, Jeremy Kemper escribi=F3:
El Martes, 12 de Agosto de 2008, Gerald Bauer escribi=F3:

What does it mean? For example, in Ruby 1.8 and 1.9 the following code
returns the same:

----------
kk=3D123;
puts "KK out of block =3D #{kk}";
1.upto(3) { puts "KK in block =3D #{kk}"; kk=3D999 };
puts "KK out of block =3D #{kk}"
----------

KK out of block =3D 123
KK in block =3D 123
KK in block =3D 999
KK in block =3D 999
KK out of block =3D 999

$ irb-1.8

=3D> 1

=3D> [2]

=3D> 2

$ irb-1.9

=3D> 1

=3D> [2]

=3D> 1

So the block arg 'a' no longer clobbers the local var 'a'.

jeremy

No sure if I understand you. Please lok at this code:


~# irb1.8
irb(main):001:0> a=3D1
1
irb(main):002:0> [2].each { a=3D3 }
[2]
irb(main):003:0> a
3


~$ irb1.9
irb(main):001:0> a=3D1
1
irb(main):002:0> [2].each { a=3D3 }
[2]
irb(main):003:0> a
3



the result is the same (but true, if I run your code in 1.8 and 1.9 result =
is=20
different, but I don't understand which is the difference between your code=
=20
and mine).



=2D-=20
I=F1aki Baz Castillo
 
I

Iñaki Baz Castillo

El Martes, 12 de Agosto de 2008, I=F1aki Baz Castillo escribi=F3:
the result is the same (but true, if I run your code in 1.8 and 1.9 result
is different, but I don't understand which is the difference between your
code and mine).

Maybe the difference occurs when the variable is passed to the block as=20
parameter ( {|a| ..} ) ?

=2D-=20
I=F1aki Baz Castillo
 
I

Iñaki Baz Castillo

Thanks a lot for so good explanation.



=2D-=20
I=C3=B1aki Baz Castillo
 
S

Stefan Lang

2008/8/12 Gerald Bauer said:
Hello,

I've created a S6/S9 version of Sam Ruby's OSCON 2008 slide deck
titled "Ruby 1.9: What to Expect (What's Changed? What's New?)" that
offers a single-web page version that in addition to offering a
full-screen slide show is easy-to-print for offline reading. (S6/S9
Tip: Use the t-key to toggle between outline and slide show view.)

Thanks!

It says "Hash Keys Now Unordered" and shows an example where
Ruby 1.8 happens to print the keys in alphabetic order.

Hash keys in 1.8 are not ordered in any documented way. In fact,
the headline should say "Hash Keys Now (Insertion) Ordered".

Stefan
 
I

Iñaki Baz Castillo

El Martes, 12 de Agosto de 2008, David A. Black escribi=C3=B3:
If you want to use a non-parameter inside a block and have it not
clobber an outside variable, you can declare it as a local variable by
putting it after a semi-colon in the parameter list:

=C2=A0 =C2=A0{|x,y,z;a| a =3D 1 } =C2=A0 =C2=A0# a is not bound to any bl= ock args but is
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0# local to the block


Could I use that to avoid the problem if I do this:

Thread.new(request) { |request| ... }

This is a big problem since the "request" into the block points to the requ=
est=20
outside, so each thread share it (dangerous). This is why I use:

Thread.new(request) { |req| ... }

Could I use this?
Thread.new(request) { |;request| ... }


Thanks.

=2D-=20
I=C3=B1aki Baz Castillo
 
I

Iñaki Baz Castillo

El Mi=C3=A9rcoles, 13 de Agosto de 2008, MenTaLguY escribi=C3=B3:
In 1.9, you don't need to. Block parameters shadow local variables,
such that this works fine:

Yeah, I know, that is why I asked a solution for 1.8 :)

Thread.new(request) { |request| ... }

In 1.9, 'request' inside and outside the block are different variables.

(I'm still not entirely sure I'd recommend calling them the same thing,
for readability's sake, but you can do it now...)

Why?

Thanks.


=2D-=20
I=C3=B1aki Baz Castillo
 
C

Charles Oliver Nutter

There's a couple errors or oddities in the slides.

Gerald said:
* Hash Keys Now Unordered

As someone else noted, hash keys have never been ordered in 1.8.6 or
earlier. The example shown is in alphabetical order purely by chance.
1.9 adds insertion ordering. JRuby also has insertion-ordered hashes
already.
* Inject Methods

This is really a larger change, the addition of to_proc to Symbol
similar to what ActiveSupport provides. It's not specific to inject.
* Decimal Is Still Not The Default

I doubt Decimal will ever be the default, no matter how people wish it.
* Break Values

This is no different than Ruby 1.8.x.
* "Nested" Methods

This is nothing new; a method defined in another method just defines on
the same class, as normal. They're not really "nested".

There's also a "Real threading" slide that confused me. Ruby 1.9 does
use real kernel threads, but they don't run in parallel.

- Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top