From: "R. Kumar" Date: 2010-01-12T22:07:28+09:00 Subject: Is 'rescue' expensive ? If i use something like: > array.count rescue array.size does the rescue set up anything internally that will make this inefficient ? I have other options too, however, i want to minimize code clutter since this situation is rare (my app says it works under 1.8.7 and 1.9). Someones using it in 1.8.6 which i learn has no array#count. Otoh, 1.9 has no array#size. Other options are : unless Array.method_defined?(:count) then class Array def count size end end end # remark: i assume this is a one time startup cost or: if array.respond_to?(:count) then array.count else array.size end # remark: evaluated each time, so cost is high My hope is that the rescue clause of the first example is only looked at by the interpreter if an error occurs, otherwise there's no penalty for it. Suggestions ? -- Posted via http://www.ruby-forum.com/.