<p>My rails model has code that is attempting to <code>define_method(method_name)</code> inside the model.</p>

<p>I keep getting:</p>

<pre><code>NoMethodError: undefined method `define_method'
</code></pre>

<p>What am I doing wrong? Am I doing this in the wrong place. I need this method attached to this model. Where else can I define this method?</p>

<p>EDIT:
For those asking to see the code:</p>

<pre><code>for field in rdev_fields
  next if self.attributes.include?(field)
  count = count + 1
  rdev_hash[field.to_sym] = self.attributes["attribute#{count}"]
  if !self.respond_to?(field) then
    define_method("#{field}") do
      self.send("attribute#{count}".to_sym)
    end
  end
end
</code></pre>

was able to cobble this together. Very little understanding of what's actually going on though.
My instance method foo is opening the class and defining bar on it so that I can then call that on my instance. More experienced folks will let us know if this is opening a can of worms at the same time.
Would be useful to know your specific use for this though.
```
```
class User < ActiveRecord::Base

  def foo
    (class << self; self; end).class_eval do
      define_method(:bar) {puts "bar"}
    end
  end
end

u = User.first
u.foo
u.bar #=> "bar"
```
```