dblock / ruby-enum

A handy way to define enums in Ruby.
MIT License
178 stars 23 forks source link

Adds support for non constant definitions #18

Closed laertispappas closed 7 years ago

laertispappas commented 7 years ago

Addresses issue #17 and adds support for non constant definitions. Although there is no example in the docs where we define enums in lowercase some are using Ruby::Enum as follows:

class State
  include Ruby::Enum

  define :created, 'Created'
end
laertispappas commented 7 years ago

@dblock Could you please review this?

dblock commented 7 years ago

I don't love relying on an exception. Maybe we can check the value being passed in? If it's an all uppercase string we do one thing, otherwise we do another? I'm not sure it's better though, what do you think?

laertispappas commented 7 years ago

Agree! I thought about it too but I didn't want o make things more complex and add if decisions based on the first character of the enum name. We could isolate the const_set in a begin rescue block but still it's cryptic to rely on the exception. I will proceed with you proposal. Thanks

dblock commented 7 years ago

This looks good, merged. Maybe release?

laertispappas commented 7 years ago

Sure I will prepare it.