[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Son of 10 things! (1.8 to 1.9 transition

David A. Black

1/16/2009 2:21:00 PM

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

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.r...
Coming in 2009: The Well-Grounded Rubyist (http://manning....)

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

9 Answers

Nit Khair

1/17/2009 5:35:00 AM

0

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.
--
Posted via http://www.ruby-....

F. Senault

1/17/2009 11:11:00 AM

0

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
--
People like us Know how to survive There's no point in living
If you can't feel the life We know when to kiss
And we know when to kill If we can't have it all Then nobody will
(Garbage, The World Is Not Enough)

Nit Khair

1/17/2009 11:25:00 AM

0

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

--
Posted via http://www.ruby-....

David A. Black

1/17/2009 11:29:00 AM

0

Hi --

On Sat, 17 Jan 2009, RK Sentinel wrote:

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

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.r...
Coming in 2009: The Well-Grounded Rubyist (http://manning....)

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

Nit Khair

1/17/2009 12:15:00 PM

0

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.
--
Posted via http://www.ruby-....

nico

1/17/2009 3:47:00 PM

0

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
--
Posted via http://www.ruby-....

Brian Candler

1/17/2009 8:30:00 PM

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
--
Posted via http://www.ruby-....

Tom Cloyd

1/18/2009 2:40:00 AM

0

Brian Candler 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 Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Lyle Johnson

1/20/2009 3:01:00 PM

0

On Sat, Jan 17, 2009 at 8:40 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:

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

Good things come to those who wait.