3

I have a Video model with a property called aspect_ratio that is an enum:

ASPECT_RATIOS = [:four_three, :sixteen_nine]

enum aspect_ratio: ASPECT_RATIOS

The property is stored as an integer.

When I access this property, I get a string representation of the enumerated symbol

video.aspect_ratio # four_three
video.aspect_ratio.class # String

However when I iterate over the model's properties using video.attributes.each_pairthe value of aspect_ratio is an integer. I need to iterate over attributes in such a way that if the attribute is an enum I get the string value, not its integer value.

The following also return its integer value:

video.read_attribute(:aspect_ratio)
video[:aspect_ratio]

Is there another way to iterate to ensure I get the string value of the enum?

Undistraction
  • 42,754
  • 56
  • 195
  • 331

1 Answers1

2

you could try the easiest way: video.public_send(:aspect_ratio)

Igor Guzak
  • 2,155
  • 1
  • 13
  • 20