lib/bindata/choice.rb
# Returns the selected data object.
Returns the selected data object.
Returns the selected data object .
def the_choice
      key = eval_param(:selection)
      if key.nil?
        raise IndexError, ":selection returned nil value"
      end
      obj = @choices[key]
      if obj.nil?
        choice_klass, choice_params = no_eval_param(:choices)[key]
        if choice_klass.nil?
          raise IndexError, "selection #{key} does not exist in :choices"
        end
        obj = choice_klass.new(choice_params, self)
        @choices[key] = obj
      end
      if key != @last_key
        if @last_key != nil
          prev = @choices[@last_key]
          if prev != nil and prev.single_value? and obj.single_value?
            obj.value = prev.value
          end
        end
        @last_key = key
      end
      obj
    end
def the_choice key = eval_param ( :selection ) if key . nil? raise IndexError , ":selection returned nil value" end obj = @choices [ key ] if obj . nil? choice_klass , choice_params = no_eval_param ( :choices ) [ key ] if choice_klass . nil? raise IndexError , "selection #{key} does not exist in :choices" end obj = choice_klass . new ( choice_params , self ) @choices [ key ] = obj end if key != @last_key if @last_key != nil prev = @choices [ @last_key ] if prev != nil and prev . single_value? and obj . single_value? obj . value = prev . value end end @last_key = key end obj end
Returns the selected data object.
Returns the selected data object .
# instantiate choice object # for single_values copy the value when the selected object changes