I'm trying to refactor the code by defining the method dynamically with args. I've tried to use Define_method but it's throwing an error and I've been forced to define define_singleton_method.
Here is my code, I want to remove all the methods with call_* prefix.
def construct_payload(id, file_name, type)
case type
when 'Radio' then call_radio(id, file_name)
when 'Pan' then call_pan(id, file_name)
end
end
def call_radio(_id, _file_name)
base(_id).merge(radio(_file_name))
end
def call_pan(_id, _file_name)
base(_id).merge(pan(_file_name))
end
def base(_id)
{
"id": _id,
}
end
def radio(file)
{
"mode": "ds",
"file": file
}
end
def pan(file)
{
"mode": "pr",
"file": file
}
end
#enter code here
Is there a way I can define call_radio and call_pan methods dynamically?