Class: Enumpath::Resolver::Simple
- Inherits:
-
Object
- Object
- Enumpath::Resolver::Simple
- Defined in:
- lib/enumpath/resolver/simple.rb
Overview
A utility for resolving a string as an index, key, or member of an enumerable
Constant Summary collapse
- NUMERIC_INDEX_TEST =
/\A\-?(?:0|[1-9][0-9]*)\z/
Class Method Summary collapse
-
.resolve(variable, enum) ⇒ Object
Attempts to resolve a string as an index, key, or member of an enumerable.
Class Method Details
.resolve(variable, enum) ⇒ Object
Attempts to resolve a string as an index, key, or member of an enumerable
15 16 17 18 19 20 21 |
# File 'lib/enumpath/resolver/simple.rb', line 15 def resolve(variable, enum) variable = variable.to_s value = rescued_dig(enum, variable.to_i) if variable =~ NUMERIC_INDEX_TEST value = rescued_dig(enum, variable) if value.nil? value = rescued_dig(enum, variable.to_sym) if value.nil? value end |