Integer to words

0 views
Skip to first unread message

kala...@bc.edu

unread,
Apr 29, 2008, 7:49:50 PM4/29/08
to Boston Ruby Group
Sorry if this isn't an appropriate use of the board, I haven't really
been around too long or been too involved.

I never found a solution for changing integers to words that I liked.
I know the ruby linguistics gem does it, but that was overkill for
what I needed so I pulled this together, and it seemed more
lightweight and more flexible than the other solutions I had come
across.

Also, I generally don't venture outside of the basic rails coding
patterns, so it was a bit of a challenge to myself to make something
different. Feel free to use the code, or provide any feedback as to
how I could make it better. I have it as an extension to the Integer
class in ActiveSupport, but it'd be easy to move it to a helper.

http://github.com/farski/rails/commit/300d58063bc4b5d0460307f35259bd2ebc3762d2

I'm thinking about adding support for decimals as well, but not today.

also, it's fun to type in really big numbers and see how they are
called.

Josh

unread,
Apr 29, 2008, 11:31:08 PM4/29/08
to Boston Ruby Group
Take a look at the 'english' gem. Not sure if that's the same
linguistics thing you're talking about.

sudo gem install -y english

In particular, English::Numerals::name(integer) sounds like what
you're looking for. Additionally, it monkey patches Integer so you do
4.english.

On Apr 29, 7:49 pm, kalaf...@bc.edu wrote:
> Sorry if this isn't an appropriate use of the board, I haven't really
> been around too long or been too involved.
>
> I never found a solution for changing integers to words that I liked.
> I know the ruby linguistics gem does it, but that was overkill for
> what I needed so I pulled this together, and it seemed more
> lightweight and more flexible than the other solutions I had come
> across.
>
> Also, I generally don't venture outside of the basic rails coding
> patterns, so it was a bit of a challenge to myself to make something
> different. Feel free to use the code, or provide any feedback as to
> how I could make it better. I have it as an extension to the Integer
> class in ActiveSupport, but it'd be easy to move it to a helper.
>
> http://github.com/farski/rails/commit/300d58063bc4b5d0460307f35259bd2...
Reply all
Reply to author
Forward
0 new messages