2010/4/2 Jesús Gabriel y Galán [email protected]
So my point is that, independently on the internal implementation of
Fixnums, the important consideration for his question is the fact that
they are inmutable, and so it’s impossible to call a method that would
modify the object. So it’s not possible to mimic the same examples as
with hashes and arrays.
Jesus.
You can get the array and hash to mimic the number, though, by calling
non
mutating methods on them.
def scope( old_hash , old_array , old_num )
puts “in scope”
p (old_hash.merge Hash[ ‘e’,5 , ‘f’,6 , ‘g’,7 ]) # => {“a”=>1,
“b”=>2,
“c”=>3, “d”=>4, “e”=>5, “f”=>6, “g”=>7}
p (old_array += [5,6,7]) # => [1, 2, 3, 4, 5,
6,
7]
p (old_num += 1) # => 8
end
hash = {“a”=>1,“b”=>2,“c”=>3,“d”=>4}
array = [1,2,3,4]
num = 7
scope( hash , array , num )
puts
puts “after scope”
p hash # => {“a”=>1, “b”=>2, “c”=>3, “d”=>4}
p array # => [1, 2, 3, 4]
p num # => 7