Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Rub 1.9: "inline rescue" doesn't work?

Reply
Thread Tools

Rub 1.9: "inline rescue" doesn't work?

 
 
Iñaki Baz Castillo
Guest
Posts: n/a
 
      03-01-2009
Hi, is there any explanation for the folowing big difference between the sa=
me=20
code in 1.8 and 1.9?:


1.

aaa =3D 123.capitalize rescue 444
=3D> 444


1.9)

aaa =3D 123.capitalize rescue 444
NoMethodError: undefined method `capitalize' for 123:Fixnum


It seems that Ruby 1.9 doesn't react on "inline rescue" as 1.8. Do I miss=20
something?

Thanks a lot.



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

 
Reply With Quote
 
 
 
 
Iñaki Baz Castillo
Guest
Posts: n/a
 
      03-02-2009
El Lunes, 2 de Marzo de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:

> It seems that Ruby 1.9 doesn't react on "inline rescue" as 1.8. Do I miss
> something?


Well, it must be something even worse since block rescue neither works:

=2D----------------
begin
aaa =3D 123.capitalize
rescue
aaa =3D 444
end
=2D-----------------
=3D> NoMethodError: undefined method `capitalize' for 123:Fixnum


Perhaps it's due to the not updated version of Ruby1.9 I'm using?:

$ irb1.9 -v
irb 0.9.5(05/04/13)

$ ruby1.9 -v
ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]


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

 
Reply With Quote
 
 
 
 
Iñaki Baz Castillo
Guest
Posts: n/a
 
      03-02-2009
El Lunes, 2 de Marzo de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:

> Perhaps it's due to the not updated version of Ruby1.9 I'm using?:
>
> $ irb1.9 -v
> irb 0.9.5(05/04/13)
>
> $ ruby1.9 -v
> ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]


Yes, it seems to be an old bug in my 1.9 version. I've upgraded to:

$ ruby1.9 -v
ruby 1.9.0 (2007-12-25 revision 14709) [i486-linux]

and the "rescue" issue has gone.


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

 
Reply With Quote
 
Brian Mitchell
Guest
Posts: n/a
 
      03-02-2009
On Sun, Mar 1, 2009 at 19:01, I=C3=B1aki Baz Castillo <> wrote=
:
> El Lunes, 2 de Marzo de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
>
>> It seems that Ruby 1.9 doesn't react on "inline rescue" as 1.8. Do I mis=

s
>> something?

>
> Well, it must be something even worse since block rescue neither works:
>
> -----------------
> begin
> =C2=A0 =C2=A0 =C2=A0 =C2=A0aaa =3D 123.capitalize
> rescue
> =C2=A0 =C2=A0 =C2=A0 =C2=A0aaa =3D 444
> end
> ------------------
> =3D> NoMethodError: undefined method `capitalize' for 123:Fixnum
>
>
> Perhaps it's due to the not updated version of Ruby1.9 I'm using?:
>
> =C2=A0$ irb1.9 -v
> =C2=A0irb 0.9.5(05/04/13)
>
> =C2=A0$ ruby1.9 -v
> =C2=A0ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]


miro:~ brian$ irb19
>> aaa =3D 123.capitalize rescue 444

=3D> 444
miro:~ brian$ ruby19 -v
ruby 1.9.2dev (2009-03-02 trunk 22700) [i386-darwin9.6.0]

Brian.

 
Reply With Quote
 
Gregory Brown
Guest
Posts: n/a
 
      03-02-2009
On Sun, Mar 1, 2009 at 6:58 PM, I=F1aki Baz Castillo <> wrote:
> Hi, is there any explanation for the folowing big difference between the =

same
> code in 1.8 and 1.9?:
>
>
> 1.
>
> aaa =3D 123.capitalize rescue 444
> =3D> 444
>
>
> 1.9)
>
> aaa =3D 123.capitalize rescue 444
> NoMethodError: undefined method `capitalize' for 123:Fixnum


>> RUBY_VERSION

=3D> "1.9.1"
>> 123.captialize rescue 444

=3D> 444

But please, don't use this technique. It creates huge debugging nightmares=
 
Reply With Quote
 
Michal Suchanek
Guest
Posts: n/a
 
      03-02-2009
2009/3/2 Gregory Brown <>:
> On Sun, Mar 1, 2009 at 6:58 PM, I=C3=B1aki Baz Castillo <> w=

rote:
>> Hi, is there any explanation for the folowing big difference between the=

same
>> code in 1.8 and 1.9?:
>>
>>
>> 1.
>>
>> aaa =3D 123.capitalize rescue 444
>> =3D> 444
>>
>>
>> 1.9)
>>
>> aaa =3D 123.capitalize rescue 444
>> NoMethodError: undefined method `capitalize' for 123:Fixnum

>
>>> RUBY_VERSION

> =3D> "1.9.1"
>>> 123.captialize rescue 444

> =3D> 444
>
> But please, don't use this technique. =C2=A0It creates huge debugging nig=

htmares.
>
> Instead, just do:
>
> aaa =3D obj.respond_to?(:capitalize) ? obj.capitalize : 444
>
>

I'd see it as a Ruby's failure that the proper check is against DRY.

Thanks

Michal

 
Reply With Quote
 
Michael Fellinger
Guest
Posts: n/a
 
      03-02-2009
On Mon, Mar 2, 2009 at 9:23 AM, I=C3=B1aki Baz Castillo <> wro=
te:
> El Lunes, 2 de Marzo de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
>
>> Perhaps it's due to the not updated version of Ruby1.9 I'm using?:
>>
>> =C2=A0 $ irb1.9 -v
>> =C2=A0 irb 0.9.5(05/04/13)
>>
>> =C2=A0 $ ruby1.9 -v
>> =C2=A0 ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]

>
> Yes, it seems to be an old bug in my 1.9 version. I've upgraded to:
>
> =C2=A0$ ruby1.9 -v
> =C2=A0ruby 1.9.0 (2007-12-25 revision 14709) [i486-linux]
>
> and the "rescue" issue has gone.


That's still ancient. The latest revision is 22705 and the last stable
release was 1.9.1.

^ manveru

 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-02-2009
Michal Suchanek wrote:

>> aaa = obj.respond_to?(:capitalize) ? obj.capitalize : 444


> I'd see it as a Ruby's failure that the proper check is against DRY.


DRY is most egregious when the duplicated components are far apart from each
other. (And hence harder to spot!) Duplicating things right next to each other
is Mostly Harmless, and it's always the next best thing if you can't think of
the final refactor.

--
Phlip
http://www.zeroplayer.com/
 
Reply With Quote
 
Gregory Brown
Guest
Posts: n/a
 
      03-02-2009
On Mon, Mar 2, 2009 at 3:18 AM, Michal Suchanek <> wrote=
:
> 2009/3/2 Gregory Brown <>:


>> But please, don't use this technique. =A0It creates huge debugging night=

mares.
>>
>> Instead, just do:
>>
>> aaa =3D obj.respond_to?(:capitalize) ? obj.capitalize : 444
>>
>>

> I'd see it as a Ruby's failure that the proper check is against DRY.


Agreed, but the costs of the elegance of using rescue as a conditional
modifier stack up fast in any moderately complex system.

-greg

--=20
Technical Blaag at: http://blog.majesticseacreature.com
Non-tech stuff at: http://metametta.blogspot.com
"Ruby Best Practices" Book now in O'Reilly Roughcuts:
http://rubybestpractices.com

 
Reply With Quote
 
Ken Bloom
Guest
Posts: n/a
 
      03-02-2009
On Mon, 02 Mar 2009 09:36:10 -0500, Gregory Brown wrote:

> On Mon, Mar 2, 2009 at 3:18 AM, Michal Suchanek <>
> wrote:
>> 2009/3/2 Gregory Brown <>:

>
>>> But please, don't use this technique. Â*It creates huge debugging
>>> nightmares.
>>>
>>> Instead, just do:
>>>
>>> aaa = obj.respond_to?(:capitalize) ? obj.capitalize : 444
>>>
>>>

>> I'd see it as a Ruby's failure that the proper check is against DRY.

>
> Agreed, but the costs of the elegance of using rescue as a conditional
> modifier stack up fast in any moderately complex system.
>
> -greg



The problem with the rescue modifier is that it lumps all types of errors
into one relatively blunt tool. A rescue(Type) modifier would really
help, and a ?. operator (like Groovy's) would resolve one of the most
common cases for a rescue modifier.

--Ken

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rub 1.8.1 and $= Patrick Gundlach Ruby 4 01-07-2004 08:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57