title: Undefined method 'array' for main:Object
body: <p>So I was just playing with blocks in ruby, and I wrote this code: </p>
  
  <pre><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
  </code></pre>
  
  <p>But it keeps giving me this error:</p>
  
  <pre><code>./tests.rb:16:in `&lt;main&gt;': undefined method `array' for main:Object (NoMethodError)
  </code></pre>
  
  <p>Why is that? I can clearly see that I defined array. I would appreciate any help, thanks!</p>