What's the difference here? (class extension on run-time)

Hi all

I’m not very experienced with Ruby yet. I have the following code (from
a Ruby on Rails project) that I have adapted from a book and modified a
bit:

class IncenseFormBuilder < ActionView::Helpers::FormBuilder
private
def self.create_tagged_field(method_name)
define_method(method_name) do |label, *args|
html_surround(label, super) # Provides the HTML code that
surrounds the form label and the method (super) that generates the input
tag(s)
end
end

field_helpers.reject{|h| h == 'hidden_field'}.concat([:select]).each

do |method_name|
create_tagged_field(method_name)
end
end
end

This code works as expected: it defines some methods on run-time and I
have those neat methods available in my views.

I wanted to edit the code in the following way to make it shorter:

class IncenseFormBuilder < ActionView::Helpers::FormBuilder
private
field_helpers.reject{|h| h == ‘hidden_field’}.concat([:select]).each
do |method_name|
define_method(method_name) do |label, *args|
html_surround(label, super) # Provides the HTML code that
surrounds the form label and the method (super) that generates the input
tag(s)
end
end
end
end

But now I get a strange “private method `text_field’ called for
#IncenseFormBuilder:0x22fd6b0” error although the code seems to do
quite the same as before? What have i missed?

Thanks for help,
Joshua