# Class redefinition

**URL:** <https://www.ruby-forum.com/t/class-redefinition/65241>\
**Category:** Rails\
**Created:** [August 17, 2006, 1:01am UTC](https://www.ruby-forum.com/t/class-redefinition/65241 "2006-08-17T01:01:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [August 17, 2006, 1:01am UTC](https://www.ruby-forum.com/t/class-redefinition/65241/1 "2006-08-17T01:01:17Z")

</div>

Hi,

Suppose I want to redefine the Ruby String class in a Rails app. In  
which  
file is it the most suitable to write the redefinition?

Thanks

Guillaume C.

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [August 17, 2006, 2:22am UTC](https://www.ruby-forum.com/t/class-redefinition/65241/2 "2006-08-17T02:22:21Z")

</div>

any file … as long its visible to your application and require for  
that  
file returns true

for example you have a file called thisfile.rb

all you have to do in that file is

class String  
def yourMethod  
#do something  
end  
end

and wherever you need it just do this

require ‘thisfile’

-daya

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [August 17, 2006, 2:28am UTC](https://www.ruby-forum.com/t/class-redefinition/65241/3 "2006-08-17T02:28:22Z")

</div>

…and “thisfile.rb” should go into the model, controller or helpers  
folder?

Guillaume C.

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [August 17, 2006, 2:37am UTC](https://www.ruby-forum.com/t/class-redefinition/65241/4 "2006-08-17T02:37:22Z")

</div>

lib

Max

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [August 17, 2006, 2:55am UTC](https://www.ruby-forum.com/t/class-redefinition/65241/5 "2006-08-17T02:55:23Z")

</div>

ok thanks.

Another question… once I start my Webrick server, the String class  
gets  
redefined well the first time but all subsequent changes goes unnoticed  
by  
the requests. I have to restart my webserver…

Why is this happening?  
Is there a way to avoid it?

Guillaume C.

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [November 7, 2006, 11:00am UTC](https://www.ruby-forum.com/t/class-redefinition/65241/6 "2006-11-07T11:00:21Z")

</div>

never got an answer

anyone?
