I need to get string name of enum state by integer value, and i do it next way
Order.states.find{|x| x[1] == data['stateId']}
Does anybody know better way to do it?
enum state: {
created: 0,
cancelled: 100,
complete: 10,
}
Order.states.key(100) => 'cancelled'
Here's a solution that removes the magic number.
Order.states.key(Order.states[:cancelled]) => 'cancelled'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With