I want to iterate over an array of strings and assign each of them a new instance of the User class, and I expect that I will have an array of User objects:
class User def name=(name) @name = name self end end original_array = ["aaa", "bbb", "bbb"] result = original_array.collect { |str| User.new.name = str }
but the result is an array of strings!
puts result.inspect # => ["aaa", "bbb", "bbb"] puts result === original_array # => true
I do not know where I was wrong?
hbin source share