From: ara.t.howard@... Date: 2006-08-03T06:38:22+09:00 Subject: Re: Can't convert String into Integer (TypeError) On Thu, 3 Aug 2006, Timothy Hunter wrote: > Okay, I'm stumped. I've been looking at this program off-and-on for 3 days > now and I can't understand why it's failing like it does. It's *supposed* to > fail, but not the way it does. > > The Image#dissolve method takes 2 arguments, an Image object and a > percentage. The percentage argument can be specified either as a number > between 0.0 and 1.0, or as a string in the form "NNN%", like "50%" for > example. In this test I'm passing "1x0%" as the percentage, which is clearly > incorrect. I expect dissolve to raise an ArgumentError exception with the > message "expected percentage, got `1x0%'". What actually happens is that I > get > > /Users/timothyhunter/Temporary/bug.rb:22:in `raise': can't convert String > into Integer (TypeError) > from /Users/timothyhunter/Temporary/bug.rb:22:in `dissolve' > from /Users/timothyhunter/Temporary/bug.rb:43 > > Line 22 is the "raise" statement. > > What am I missing? jib:~ > ruby -r RMagick -e' p Magick::Image.instance_methods.grep(/raise/) ' ["raise"] btw, seems like you could get away with something like: pct = Float(pct) rescue (Float(pct.to_s.delete('%'))/100) r = 0.0 .. 1.0 pct = [r.min, pct].max pct = [r.max, pct].min cheers. -a -- we can never obtain peace in the outer world until we make peace with ourselves. - h.h. the 14th dali lama