S
Sven S.
Hi
Cumbersome title, here's what I'd like to do both elegantly and without
monkey patching Hash:
Say, I need to pass a hash to a method:
mymethod :this => 'green'
Now I'd like to include a second hash member only if a condition is met:
mymethod :this => 'green, :that => ('blue' if condition)
This of course leaves ":that => nil" in the hash if the condition is not
met - which is no good, the key should just not be present at all. I
could delete_if after that, but isn't there a more elegant way?
Thanks for your ideas!
Cumbersome title, here's what I'd like to do both elegantly and without
monkey patching Hash:
Say, I need to pass a hash to a method:
mymethod :this => 'green'
Now I'd like to include a second hash member only if a condition is met:
mymethod :this => 'green, :that => ('blue' if condition)
This of course leaves ":that => nil" in the hash if the condition is not
met - which is no good, the key should just not be present at all. I
could delete_if after that, but isn't there a more elegant way?
Thanks for your ideas!