So I was just playing with blocks in ruby, and I wrote this code:
#!/usr/bin/env ruby
def my_map ary
a = ary.clone
if block_given?
while element = a.shift
yield element
end
else
ary
end
end
array = [1, 2, 3, 4, 5]
my_map array { |e|
puts e * 2
}
p array
But it keeps giving me this error:
./tests.rb:16:in `<main>': undefined method `array' for main:Object (NoMethodError)
Why is that? I can clearly see that I defined array. I would appreciate any help, thanks!