Is it valid syntax to have a Ruby class extend itself, but under a separate module? For instance, I have an ErrorsController
class..
class ErrorsController < ApplicationController
....
end
But I want to have a different behavior if under a module..
class Share::ErrorsController < ErrorsController
....
end
Here ErrorsController is extending ErrorsController, which works fine. But then I wrote it in long form:
module Share
class ErrorsController < ErrorsController
end
end
There seemed to be problems sometime..
To unambiguously refer to the "top-level" ErrorsController, the typical technique is to add two colons before it. So for example:
module Share
class ErrorsController < ::ErrorsController
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