-
-
Save maxjacobson/7584201 to your computer and use it in GitHub Desktop.
| # gem install numbers_in_words | |
| require 'numbers_in_words' | |
| require 'numbers_in_words/duck_punch' | |
| class Array | |
| def method_missing(m) | |
| self[m.to_s.gsub(/\_/, ' ').in_numbers - 1] | |
| end | |
| end | |
| nums = (1..100).to_a | |
| puts nums.first #=> 1 | |
| puts nums.second #=> 2 | |
| puts nums.third #=> 3 | |
| puts nums.fourth #=> 4 | |
| puts nums.thirty_five #=> 35 | |
| puts nums.thirty_fifth #=> 30 (bug) | |
| # I just want to acknowledge that I'm using `#=>` incorrectly. That's supposed to indicate the return value, but I'm using it to indicate the output. |
oh, I see now that you said that
so that means I can use .second in my rails apps, who knew?
but I maintain that it's a bug because the interface is inconsistent. I don't mean it's a bug in that gem, I mean a bug in my implementation. if I can do [].second then I should be able to do [].thirty_fifth
Yes, if you're tying the bug to your interface, then I agree completely. We both now know that the numbers_to_words gem cannot handle "-nd" || "-th processing, so that's something you'll have to account for.
Either way, this is a cool implementation and was a good excuse to pry into someone else's code.
GET IT?! ❤️ ❤️ ❤️
@cjlwired thanks for breaking it down btw, I never would have thought it was leaning on active support if you hadn't dug into the source <3
@cjlwired I'll double check later but ... I'm pretty sure I'm not using active support. unless active support is a dependency of numbers_in_words