Son of 10 things! (1.8 to 1.9 transition)

D

David A. Black

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 (http://manning.com/black2)

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

RK Sentinel

David said:
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:
=> 97
and in 1.9:
=> "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.
 
F

F. Senault

Le 17 janvier 2009 à 06:35, RK Sentinel a écrit :
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().

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
 
R

RK Sentinel

F. Senault said:
Le 17 janvier 2009 � 06:35, RK Sentinel a �crit :

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.)
 
D

David A. Black

Hi --

Thanks. I just caught this in your article:



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.

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 (http://manning.com/black2)

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

RK Sentinel

David said:
Hi --

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.
 
T

Tom Cloyd

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

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

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top