I want to pass a symbol into a method and have it
def block
@something = Something.find(1)
hsh = {:type => :method_to_perform}
hsh.each { |k, v| nil_test k, v }
end
def nil_test k, v
@something.try(:k) ? (@k = @something.k.v) : nil
end
I’m running into one or maybe two issues, first I think passing the symbol isn’t acting as a method on @something. How do you pass a symbol and have it act as a method into another block?
Second, I want the key to become the symbol, in others words in the above example I want @k to be @type, not @k. Know how to solve this problem?
You need to use
send(orpublic_send):You might as well just do
which is equivalent.