Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The Enum implementation seems full of caveats.

1. It saves values as integers in the database, meaning that removing properties involves explicit setting, and reordering them requires custom migration code.

2. "Avoid using the same names inside different enums in the same class! Doing so will leave Active Record very confused!"[1]

That's right, we can't use the same enum name to two different fields because ActiveRecord might get confused. That's kind of poor, isn't it?

3. Having to pass a macro that'll return the right integer instead of the symbol itself? Really?

This all seems really unwieldy, especially in the face of Enumerize(https://github.com/brainspec/enumerize). It's got none of these caveats. Is there some strength to the Rails enums that Enumerize doesn't capitalize on, other than size constraints by using Int instead of String?

[1] http://brewhouse.io/blog/2013/12/17/whats-new-in-rails-4-1.h...



Yes it's disappointing, above all considering that a better implementation is achievable in twenty lines of code in a model




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: