Hi Maxim,
Everything in the `on()` block is evaluated in the context of a SSHKit handler, by default this is the Net::SSH handler. If you really need to do what you are doing, you can create your own class with more methods, and force Capistrano to use that runner for the backend.
Better would be to write your methods in a way that they return a SSHKit::Command, so that you could do something like:
execute InitdHandler.new('handler', 'bin/handler', nil, start_env: 'PATH=/opt/ruby/shims:$PATH RUBY_ENV=production').install
Where the #install method returns the aforementioned SSHKit::Command.
If you go this way, then you'll be able to unit test that InitdHandler#install returns the correct command, and it allows you to keep your code isolated.
The Ruby autoloading code will not care if your modules are defined in our namespaces or not, so it should "just work".