Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ArgumentError when Fallbacks#map used as in Hash #570

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/i18n/locale/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ def [](locale)
super || store(locale, compute(locale))
end

def map(mappings)
mappings.each do |from, to|
from, to = from.to_sym, Array(to)
to.each do |_to|
@map[from] ||= []
@map[from] << _to.to_sym
def map(*args, &block)
if args.count == 1 && !block_given?
mappings = args.first
mappings.each do |from, to|
from, to = from.to_sym, Array(to)
to.each do |_to|
@map[from] ||= []
@map[from] << _to.to_sym
end
end
else
@map.map(*args, &block)
end
end

Expand Down
12 changes: 12 additions & 0 deletions test/locale/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,15 @@ def setup
end
end
end

class I18nFallbacksHashCompatibilityTest < I18n::TestCase
def setup
super
@fallbacks = Fallbacks.new(:'en-US', :"de-AT" => :"de-DE")
end

test "map is compatible with Hash#map" do
result = @fallbacks.map { |key, value| [key, value] }
assert_equal([[:"de-AT", [:"de-DE"]]], result)
end
end