# Howto Overwrite existing Ruby Class via Rails app?

**URL:** <https://www.ruby-forum.com/t/howto-overwrite-existing-ruby-class-via-rails-app/169216>\
**Category:** Rails\
**Created:** [May 31, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/howto-overwrite-existing-ruby-class-via-rails-app/169216 "2009-05-31T22:55:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jermaine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Jermaine](https://www.ruby-forum.com/u/Jermaine)\
**Post date:** [May 31, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/howto-overwrite-existing-ruby-class-via-rails-app/169216/1 "2009-05-31T22:55:22Z")

</div>

Hello Everyone,

in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following  
code:

* * *

class Date

module Format # :nodoc:

```
MONTHS = {
  'january' => 1, 'february' => 2, 'march' => 3, 'april' =>

```

## 4, ‘may’ =\> 5, ‘june’ =\> 6, ‘july’ =\> 7, ‘august’ =\> 8, ‘september’=\> 9, ‘october’ =\>10, ‘november’ =\>11, ‘december’ =\>12 }

How can I “overwrite” these values via my rails app? I’m trying to  
submit a foreign date to the database, so I want to overwrite  
(translate) this piece out of the format.rb file in my rails app, so  
that it understands which month I’m talking about.

Any suggestions/tips how I can fix this in a smart/efficient way?

Many Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Jermaine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Jermaine](https://www.ruby-forum.com/u/Jermaine)\
**Post date:** [May 31, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/howto-overwrite-existing-ruby-class-via-rails-app/169216/2 "2009-05-31T23:19:57Z")

</div>

Look for Rails i18n helpers, they do what you’re looking for.

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

---

<div class="post-metadata">

**Author:** ![Jermaine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Jermaine](https://www.ruby-forum.com/u/Jermaine)\
**Post date:** [May 31, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/howto-overwrite-existing-ruby-class-via-rails-app/169216/3 "2009-05-31T23:31:04Z")

</div>

No that’s not the problem, in fact I’am using I18n. But that only  
works for translating /localizing your data from the database.  
But now I’m trying to Post data to the database. So for instance, if I  
would have a form with a text field: date\_attended (\<%=  
f.text\_field :date\_attended%\> and would post the following ‘SPANISH’  
date to the database: 10 Abril 2009 (-\> which is April 10, 2009 in  
English) The database won’t understand this.

So therefore I need to change this file: 1.8/usr/lib/ruby/1.8/date/  
format.rb, because when I do that it works, but I want to do it via my  
rails app. I want to overwrite it there, but have no idea how. I was  
also thinking of maybe translating the months in the model itself, so  
that the database understands which month I’m talking about. But also  
I have no idea how to implement this in my code. I need (code)samples/  
guidance, any suggestion is welcome.

On May 31, 11:19 pm, Maurício Linhares [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Jermaine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Jermaine](https://www.ruby-forum.com/u/Jermaine)\
**Post date:** [June 1, 2009, 3:49am UTC](https://www.ruby-forum.com/t/howto-overwrite-existing-ruby-class-via-rails-app/169216/4 "2009-06-01T03:49:42Z")

</div>

create a new file under /lib directory … i.e /lib/format.rb  
then overwrite from the file

class Date  
module format  
MONTHS = { } # overwrite here  
end  
end

overwriting a constant will result a warning!
