Permalink
Browse files

Ruby 1.9.2: avoid Array#to_s and Array(nil)

  • Loading branch information...
1 parent c44fb4c commit 7ad461b44dabb586fbad190493ac4ecd96104597 @jeremy jeremy committed Nov 9, 2009
Showing with 13 additions and 4 deletions.
  1. +13 −4 activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb
@@ -195,10 +195,19 @@ def default_exception_handler(exception, locale, key, options)
# Merges the given locale, key and scope into a single array of keys.
# Splits keys that contain dots into multiple keys. Makes sure all
# keys are Symbols.
- def normalize_translation_keys(locale, key, scope)
- keys = [locale] + Array(scope) + [key]
- keys = keys.map { |k| k.to_s.split(/\./) }
- keys.flatten.map { |k| k.to_sym }
+ def normalize_translation_keys(*keys)
+ normalized = []
+ keys.each do |key|
+ case key
+ when Array
+ normalized.concat normalize_translation_keys(*key)
+ when nil
+ # skip
+ else
+ normalized.concat key.to_s.split('.').map { |sub| sub.to_sym }
+ end
+ end
+ normalized
end
end
end

1 comment on commit 7ad461b

Contributor

rymai commented on 7ad461b Nov 9, 2009

Great recursion! :)

Please sign in to comment.