Class: Compendium::ParamWithChoices
- Defined in:
- lib/compendium/param_types.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(obj, choices) ⇒ ParamWithChoices
constructor
A new instance of ParamWithChoices.
- #value ⇒ Object
Methods inherited from Param
#==, #boolean?, #date?, #dropdown?, #nil?, #radio?, #scalar?, #to_f, #to_i
Constructor Details
#initialize(obj, choices) ⇒ ParamWithChoices
Returns a new instance of ParamWithChoices.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/compendium/param_types.rb', line 33 def initialize(obj, choices) @choices = choices if @choices.respond_to?(:call) # If given a proc, defer determining values until later. index = obj else index = obj.numeric? ? obj.to_i : @choices.index(obj) raise IndexError if (!obj.nil? && index.nil?) || index.to_i.abs > @choices.length - 1 end super(index) end |
Instance Method Details
#value ⇒ Object
47 48 49 |
# File 'lib/compendium/param_types.rb', line 47 def value @choices[self] end |