# Demonstrating the use of const_get() and caller() to build a smarter delegation pattern.# Let's pretend this is a lot more complicated and in some other file.classImapProfiledefself.config
{:username => "todb",
:password => "Shadowfax"# Unguessable!
}
endend# This too.classImapSendUserNameCmddefself.data
username =ImapProfile.config[:username]
[username].pack("m*")
endendmoduleActionHandlerdefmy_protocolself.class.name.to_s.split("::").lastenddefcaller_action_to_constant
caller[1] =~/`([^']+?)'/$1=~/^do_(client|server)_(.*)/$2.split("_").map {|s| s.capitalize}.joinenddefaction_executor(args={})Kernel.const_get(my_protocol + caller_action_to_constant +"Cmd").send:dataendendmoduleAppManagerclassImapincludeActionHandlerdefget_profile_paramsKernel.const_get(my_protocol +"Profile").send:configenddefdo_client_send_user_name(args={})action_executor(args)
endendend@app=AppManager::Imap.new