J
Joao Silva
Hi.
I have following problem:
VALUES = [['value 1', 1], ['value 2', 2], ['value 3', 3]]
I need a function that returns 'value 1' if I call the function with
parameter 1.
I tried this:
def value_name(value)
VALUES.select {|v| v[1] == 1}[0][0]
end
so value_name(1) returns 'value 1' but is there something more error
tolerant? E.g. returning '' if value isn't present instead of throwing
an error?
Changing the structure of VALUES is no option, I need exactly this
structure for options_for_select from the Rails framework
Thanks in advance
Andreas
I have following problem:
VALUES = [['value 1', 1], ['value 2', 2], ['value 3', 3]]
I need a function that returns 'value 1' if I call the function with
parameter 1.
I tried this:
def value_name(value)
VALUES.select {|v| v[1] == 1}[0][0]
end
so value_name(1) returns 'value 1' but is there something more error
tolerant? E.g. returning '' if value isn't present instead of throwing
an error?
Changing the structure of VALUES is no option, I need exactly this
structure for options_for_select from the Rails framework
Thanks in advance
Andreas