Forum: Ruby on Rails Howto Overwrite existing Ruby Class via Rails app?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jermaine (Guest)
on 2009-06-01 00:55
(Received via mailing list)
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!
Maurício L. (Guest)
on 2009-06-01 01:19
(Received via mailing list)
Look for Rails i18n helpers, they do what you're looking for.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
Jermaine (Guest)
on 2009-06-01 01:31
(Received via mailing list)
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>
Erdwin L. (Guest)
on 2009-06-01 05:49
(Received via mailing list)
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!
This topic is locked and can not be replied to.