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

**URL:** <https://www.ruby-forum.com/t/whats-the-difference-here-class-extension-on-run-time/89518>\
**Category:** Ruby\
**Created:** [March 20, 2007, 11:47pm UTC](https://www.ruby-forum.com/t/whats-the-difference-here-class-extension-on-run-time/89518 "2007-03-20T23:47:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 20, 2007, 11:47pm UTC](https://www.ruby-forum.com/t/whats-the-difference-here-class-extension-on-run-time/89518/1 "2007-03-20T23:47:07Z")

</div>

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
