How can I dynamically set without having to write the same code all over.
Right now the code looks like this:
def initialize(keywords: keywords, title: t
def initialize(keywords: nil, title: nil, url: nil, adsetting: nil)
local_variables.each do |k|
v = eval(k.to_s)
instance_variable_set("@#{k}", v) unless v.nil?
end
end
or following John Ledbetter and Cary Swoveland's suggestion:
def initialize(keywords: nil, title: nil, url: nil, adsetting: nil)
method(__method__).parameters.each do |type, k|
next unless type == :key
v = eval(k.to_s)
instance_variable_set("@#{k}", v) unless v.nil?
end
end