Class: Enumbler::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/enumbler/collection.rb

Overview

Not sure if this will be needed but was leaning toward a custom wrapper for our array holding the enumbles for our model. As it is, allows you to query them based on the enum:

Color.enumbles.black # => [Enumbler::Enumble]

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



12
13
14
15
16
17
# File 'lib/enumbler/collection.rb', line 12

def method_missing(method_name, *args, &)
  enumble = find { |e| e.enum == method_name }
  return enumble if enumble.present?

  super
end

Instance Method Details

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/enumbler/collection.rb', line 19

def respond_to_missing?(method_name, *args, &)
  enumble = find { |e| e.enum == method_name }
  enumble.present? || super
end