Son of 10 things! (1.8 to 1.9 transition)

Hi –

I’ve posted an update to my recent “10 things to be aware of” post
about the Ruby 1.8 to 1.9 transition:

http://dablog.rubypal.com/2009/1/16/son-of-10-things-to-be-aware-of-in-ruby-1-9

It includes some new “things”, and some links as suggested here on
ruby-talk.

Thanks to all for the feedback on the original!

David


David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (The Well-Grounded Rubyist)

http://www.wishsight.com => Independent, social wishlist management!

David A. Black wrote:

Hi –

I’ve posted an update to my recent “10 things to be aware of” post
about the Ruby 1.8 to 1.9 transition:

Thanks. I just caught this in your article:

Also, kind of along the same lines, the ?-notation now gives a character rather >than a code. In 1.8:

?a
=> 97
and in 1.9:

?a
=> “a”

Recently, I had asked someeone on this forum to confirm that “?” still
works like before, since I use it a lot to check keystrokes in my app,
and I hope to keep the rework to a minimum when porting to 1.9. He
checked out and confirmed it does return a Fixnum in 1.9.

(i.e, ?\C-a or ?\M-a etc.)

So apparently that was wrong information.

One piece of feedback:

David, when you say "In 1.8, X == 1 and now in 1.9, X == 2 " it would
help us if you would say what we should now do to get the earlier
result.

Thanks,
Sent.

e.g.
When I check keystrokes, I do:

case ch

when ?\C-a:
do this
when ?\C-b:
do that
end

Now do I hardcode the ascii values ? Or do a convert back to Fixnum
(ord(), iirc). ?\C-a.ord().

Thx.

Le 17 janvier 2009 à 06:35, RK Sentinel a écrit :

(ord(), iirc). ?\C-a.ord().
To can also convert ch (a few keystrokes less) :

case ch.chr
when ?\C-a …

On the other hand, the use of ‘:’ with when is also deprecated, IIRC.

Fred

F. Senault wrote:

Le 17 janvier 2009 � 06:35, RK Sentinel a �crit :

(ord(), iirc). ?\C-a.ord().
To can also convert ch (a few keystrokes less) :

case ch.chr
when ?\C-a …

On the other hand, the use of ‘:’ with when is also deprecated, IIRC.

Fred

ch.chr only works for values < 256. After that it gives an out of range.

I very often trap Ncurses’ keys such as KEY_UP DOWN, RIGHT and LEFT.
They won’t work in this case. Same for function keys etc.

(Yes, I was quite surprised to see the “:” deprecation in David’s
article (i had missed it elsewhere), I use it frequently in case
statements, I thought it was good style to use it.)

Hi –

On Sat, 17 Jan 2009, RK Sentinel wrote:

and I hope to keep the rework to a minimum when porting to 1.9. He
checked out and confirmed it does return a Fixnum in 1.9.

(i.e, ?\C-a or ?\M-a etc.)

So apparently that was wrong information.

I believe so:

$ irb19
irb(main):001:0> ?a
=> “a”
irb(main):002:0> RUBY_DESCRIPTION
=> “ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203)
[i386-darwin9.5.0]”

One piece of feedback:

David, when you say "In 1.8, X == 1 and now in 1.9, X == 2 " it would
help us if you would say what we should now do to get the earlier
result.

Do you mean the block examples? The semantics are so different that
it’s hard to discuss it in terms of emulating 1.8 behavior. For
example:

x = 1
[2,3].each {|x| } # 1.8: x is 3, 1.9: x is 1

In order to get the outer x to be 3, you’d do:

x = 1
[2,3].each {|y| x = y }

which is such a different technique that I’d be wary of describing it
as the equivalent of the 1.8 semantics.

David


David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (The Well-Grounded Rubyist)

http://www.wishsight.com => Independent, social wishlist management!

David A. Black wrote:

Hi –

On Sat, 17 Jan 2009, RK Sentinel wrote:

and I hope to keep the rework to a minimum when porting to 1.9. He
checked out and confirmed it does return a Fixnum in 1.9.

(i.e, ?\C-a or ?\M-a etc.)

So apparently that was wrong information.

I believe so:

$ irb19
irb(main):001:0> ?a
=> “a”
irb(main):002:0> RUBY_DESCRIPTION
=> “ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203)
[i386-darwin9.5.0]”

One piece of feedback:

David, when you say "In 1.8, X == 1 and now in 1.9, X == 2 " it would
help us if you would say what we should now do to get the earlier
result.

Do you mean the block examples? The semantics are so different that
it’s hard to discuss it in terms of emulating 1.8 behavior. For
example:

No, the x example I mentioned was just an example. I meant more like the
fact that:

str[0] no longer gives a Fixnum. So now the reader is wondering: how do
i get my Fixnum.

The case of the “:” is okay - just remove it.

Thanks, Sent.

RK Sentinel wrote:

str[0] no longer gives a Fixnum. So now the reader is wondering: how do
i get my Fixnum.

str.getbyte 0

RK Sentinel wrote:

str[0] no longer gives a Fixnum. So now the reader is wondering: how do
i get my Fixnum.

“a”.ord

97

On Sat, Jan 17, 2009 at 8:40 PM, Tom C. [email protected] wrote:

And that, folks, is how I EXPECTED things to work, when I first came to
Ruby.

Good things come to those who wait.

Brian C. wrote:

RK Sentinel wrote:

str[0] no longer gives a Fixnum. So now the reader is wondering: how do
i get my Fixnum.

“a”.ord

97

And that, folks, is how I EXPECTED things to work, when I first came to
Ruby.

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< [email protected] >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)