i trying parameter validation outside of rails. def create_statement(action, ...) valid_one_of(action, ['add', 'move', 'delete']) ... end validation method: def valid_one_of(input, valid_values) return true if valid_values.include?(input) raise "#{input} not valid value #{input.var_name}" end sample call: create_statement('bob') so output be: bob not valid value action the problem how input.var_name ? i workaround pass valid_one_of(action, ['add', 'move', 'delete'], 'action') (and use 3rd parm output) doesn't seem feels bit redundant. if not possible access variable name there more dry coding style workaround? i don't know of way name of local variable, , if could, name want? name of parameter define on method definition? name of variable in caller? i don't think "work-around" horrible, suggest couple of slight variations might read littl...
Comments
Post a Comment