From 028577d3a05230382aca62c80a70700469a52268 Mon Sep 17 00:00:00 2001 From: idanab-simplee <“idanabrashkin@simplee.com”> Date: Sun, 9 May 2021 16:39:26 +0300 Subject: [PATCH] fix a bug of rails trying to use to_ary function. https://bugs.ruby-lang.org/issues/5759 There is no to_ary function for Enum::EnumValue, but it does respond to to_ary calls with method_missing. For example, [STATUSES.some_enum_status].flatten will fail on `undefined method 'to_ary'`. So this is meant to indicate rails to not use to_ary on this object --- lib/enum/enum_value.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/enum/enum_value.rb b/lib/enum/enum_value.rb index 1d2ea48..1b6599f 100644 --- a/lib/enum/enum_value.rb +++ b/lib/enum/enum_value.rb @@ -92,6 +92,10 @@ def method_missing(method, *args, &block) end end + def respond_to_missing?(method, *) + method.to_s == 'to_ary' ? false : super + end + private def const_to_translation(name) # From Rails' ActiveSupport String#underscore