From 59ba94e8a2e6e88cdf4e13d34e18fc7c53265407 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 3 Dec 2013 19:57:44 -0200 Subject: Change delimiter check order: first check if it is present This reads a lot better, and we won't need to try start_with? for blank delimiters. Also rename method name to read better. --- .../lib/active_support/number_helper/number_to_phone_converter.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/number_helper') diff --git a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb index 045f86c10f..4c33c30772 100644 --- a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb @@ -24,12 +24,12 @@ module ActiveSupport def convert_without_area_code(number) number.gsub!(/(\d{0,3})(\d{3})(\d{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3") - number.slice!(0, 1) if begins_with_delimiter?(number) + number.slice!(0, 1) if start_with_delimiter?(number) number end - def begins_with_delimiter?(number) - number.start_with?(delimiter) && !delimiter.blank? + def start_with_delimiter?(number) + delimiter.present? && number.start_with?(delimiter) end def delimiter -- cgit v1.2.3