How can I have a concern that I've written like this:
module Concerns
module MyConcern
extend ActiveSupport::Concern
...
def my_concern_magic(arg0,arg1)
#exciting stuff here
end
end
end
that is included in a model that overloads my_concern_magic
? E.g.
class User
include Concerns::MyConcern
...
def my_concern_magic(arg0)
arg1 = [1,2,3]
my_concern_magic(arg0,arg1)
end
end
Overloaded methods are differentiated based on the number and type of the parameters passed as arguments to the methods. You can not define more than one method with the same name, Order and the type of the arguments. It would be compiler error. The compiler does not consider the return type while differentiating the overloaded method.
method overloading with Type Promotion If a class has multiple methods having same name but different in parameters, it is known as Method Overloading. If we have to perform only one operation, having same name of the methods increases the readability of the program.
A user can implement function overloading by defining two or more functions in a class sharing the same name.
Since including a module inserts it into the ancestor chain, you can just call super
:
class User
include Concerns::MyConcern
def my_concern_magic(arg0)
arg1 = [1, 2, 3]
super(arg0, arg1)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With