Here I have defined three scopes daily_report monthly_report weekly_report
The above code dynamically generates the names of three functions and then passes parameters to them.
a.send(method_name,arg1,arg2,...)
Many parameters can be given here. The first parameter is the method name, and the following parameters are all parameters required by the method.
Then you can generate specific functions based on opt, if the functions are the same thing. Just use optional parameters for parameters.
Ruby accepts any number of parameters. You must add a * sign before a parameter. In the code of the method, this parameter is represented as an array, which contains 0 or more parameters passed to this position.
It’s ok.
For details, you can read the book Ruby Metaprogramming. It will tell you how to abstract it.
Here I have defined three scopes daily_report monthly_report weekly_report
The above code dynamically generates the names of three functions and then passes parameters to them.
Many parameters can be given here. The first parameter is the method name, and the following parameters are all parameters required by the method.
Then you can generate specific functions based on opt, if the functions are the same thing. Just use optional parameters for parameters.
Ruby accepts any number of parameters. You must add a * sign before a parameter. In the code of the method, this parameter is represented as an array, which contains 0 or more parameters passed to this position.