Skip to content

Conversation

briespoke
Copy link

Firstly, thank you for writing this module. It has improved the performance of my employer's application greatly.

We generally expect that a setter can accept a value from its own getter. However, when using ActiveEnum.use_name_as_value = true, enums must be written as either symbols or integers. Consider the following situation:

person = Person.new(sex: :male)
puts person.sex # "Male"
person.sex = person.sex
puts person.sex # nil

This behavior is counter-intuitive: a leaky abstraction. Particularly, it causes issues saving form data. This commit makes an enum accept strings, symbols and integers, fixing the leaky abstraction.

Take care and thank you for reviewing this request.

@adzap
Copy link
Owner

adzap commented Oct 9, 2016

In principal I can see this would make things more consistent. The problem is it interferes with normal typecasting of strings to integers which can be passed to a write method in various scenarios. The result could be a nil when assigning a '1' for example. Not what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants