From a3f96f16f48dcdb8364d941f760c159ee136d36e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 22 Oct 2010 17:31:28 -0700 Subject: save a few method calls --- activesupport/lib/active_support/multibyte/chars.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 0820579bec..f9607f1aaf 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -270,13 +270,14 @@ module ActiveSupport #:nodoc: @wrapped_string[*args] = replace_by else result = Unicode.u_unpack(@wrapped_string) - if args[0].is_a?(Fixnum) + case args.first + when Fixnum raise IndexError, "index #{args[0]} out of string" if args[0] >= result.length min = args[0] max = args[1].nil? ? min : (min + args[1] - 1) range = Range.new(min, max) replace_by = [replace_by].pack('U') if replace_by.is_a?(Fixnum) - elsif args.first.is_a?(Range) + when Range raise RangeError, "#{args[0]} out of range" if args[0].min >= result.length range = args[0] else -- cgit v1.2.3