I have items that can be one of several attributes like red, yellow, green (more complex than this) and they have corresponding is_red, is_yellow, is_green booleans.
I'd like to have an api function to change this value where I pass for example:
id: 12
type: red
in my function have:
item=Item.find(id)
if item.is_ + type == true
item.is_ + type=false
end
How would I do this?
thx in advance
Use send
item = Item.find(id)
if item.send(:"is_#{type}") == true
item.send(:"is_#{type}=", false)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With