title: Can you access Ruby variables with outer scope inside of methods?
body: <p>I'm learning Ruby and practicing by writing a Caesar cipher. Here's my code so far:</p>
  
  <pre><code>print "Enter rotation: "
  rotation = gets.chomp
  print "Enter string to encrypt: "
  string = gets.chomp
  
  def encrypt
      keys = (' '..'z').to_a
      values = (' '..'z').to_a.rotate(rotation)
      hash = Hash[keys.zip(values)]
      chars = string.split('')
      encrypted_chars = chars.collect { |char| hash[char] }
      encryptd_string = encrypted_chars.join
  end
  
  puts "Encrypted string: " + encrypt
  </code></pre>
  
  <p>It's saying that I don't have access to the <code>rotation</code> variable inside of the <code>encrypt</code> method. <code>NameError: undefined local variable or method 'rotation' for main:Object</code>.</p>
  
  <p>From what I understand, <code>rotation</code> is a local variable with outer scope, and should be accessible inside of the <code>encrypt</code> method. Obviously something is wrong with that reasoning, so could someone explain what's wrong?</p>