Why does this work the way it does? I thought it had something to do with pass-by-reference/value, but that's not the case. Does it have something to do with the new block scopes?
def strip_ids(array)
array.each{ |row| row.reject! {|k, v| k =~ /_id/ } }
end
class Foo
attr_accessor :array
def initialize
@array = []
@array << { :some_id => 1, :something => 'one' }
@array << { :some_id => 2, :something => 'two' }
@array << { :some_id => 3, :something => 'three'}
end
end
foo = Foo.new
puts strip_ids(foo.array).inspect
puts foo.array.inspect
##########################
#
# Output in ruby 1.8.7
#
# [{:some_id=>1, :something=>"one"}, {:some_id=>2, :something=>"two"}, {:some_id=>3, :something=>"three"}]
#
#
# Output in ruby 1.9.1
#
# [{:something=>"one"}, {:something=>"two"}, {:something=>"three"}]
#