Skip to content

Instantly share code, notes, and snippets.

@ozgun
Created December 5, 2012 09:40
Show Gist options
  • Select an option

  • Save ozgun/4214325 to your computer and use it in GitHub Desktop.

Select an option

Save ozgun/4214325 to your computer and use it in GitHub Desktop.
Niye çalışmaz?
# Yukarıdaki kod çalıştırıldığında şöyle bir hata alınıyor.
# NoMethodError: undefined method `[]=' for 1:Fixnum
# from (pry):2:in `block in __pry__'
[1,2].inject({}) do |memo, obj|
memo[obj] = obj
end
# Ama aşağıdaki şekilde "merge" ile yazarsam çalışıyor ve şöyle bir çıktı üretiyor beklendiği üzere: {1=>1, 2=>2}
[1,2].inject({}) do |memo, obj|
memo.merge(obj => obj)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment