title: How do I dynamically add an attr_reader
body: <p>I expect the following code to work as expected but it gives me a NoMethodError (private method `foo' called for #&lt;MyClass...)</p>
  
  <pre><code>class MyClass
  end
  
  my_object = MyClass.new
  
  my_object.instance_variable_set(:@foo, "bar")
  MyClass.send("attr_reader", :foo)
  
  puts my_object.foo
  </code></pre>
  
  <p>The problem is I'm using literally identical code in a larger application and it works exactly as I expect, but when I simplify it to this most basic example it fails.</p>
  
  <p>(I understand there are many other ways to do what I'm doing in Ruby)</p>