Skip to content

Instantly share code, notes, and snippets.

@mamantoha
Last active December 17, 2015 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamantoha/5590705 to your computer and use it in GitHub Desktop.
Save mamantoha/5590705 to your computer and use it in GitHub Desktop.
Bug with Ruby Hash
#!/usr/local/bin/ruby -w
translated_files = Hash.new{ |h, k| h[k] = [] }
common_dir = "/en"
langs = ['ru', 'uk']
dest_files = ['/en/share/messages/common.properties', '/en/strings/enterprise/service.properties']
langs.each do |lang|
dest_files.each do |file|
translated_files[lang] << { dest: file }
end
end
translated_files1 = {"ru"=>
[{:dest=>"/en/share/messages/common.properties"},
{:dest=>"/en/strings/enterprise/service.properties"}],
"uk"=>
[{:dest=>"/en/share/messages/common.properties"},
{:dest=>"/en/strings/enterprise/service.properties"}]}
puts translated_files == translated_files1
puts
puts "translated_files"
translated_files.each_pair do |language, files|
files.each do |file|
puts file[:dest]
file[:dest].sub!(common_dir, '')
end
end
puts
puts "translated_files1"
translated_files1.each_pair do |language, files|
files.each do |file|
puts file[:dest]
file[:dest].sub!(common_dir, '')
end
end
$ ruby lolhash.rb
true
translated_files
/en/share/messages/common.properties
/en/strings/enterprise/service.properties
/share/messages/common.properties
/strings/enterprise/service.properties
translated_files1
/en/share/messages/common.properties
/en/strings/enterprise/service.properties
/en/share/messages/common.properties
/en/strings/enterprise/service.properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment