Method: RightConf::Platform#dispatch

Defined in:
lib/rconf/platform.rb

#dispatch(*args, &blk) ⇒ Object

Call platform specific implementation of method whose symbol is returned by the passed in block. Arguments are passed through. e.g.

Platform.dispatch(2) { :echo }

will result in ‘echo_linux(2)’ being executed in self if running on linux, ‘echo_windows(2)’ if running on Windows and ‘echo_darwin(2)’ if on Mac OS X. Note that the method is run in the instance of the caller.

Parameters

args

Pass-through arguments

Block

Given block should not take any argument and return a symbol for the method that should be called

Return

res(ObjecT)

Result returned by platform specific implementation



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rconf/platform.rb', line 78

def dispatch(*args, &blk)
  raise "Platform.dispatch requires a block" unless blk
  binding = blk.binding.eval('self')
  meth = blk.call
  target = dispatch_candidates(meth).detect do |candidate|
    binding.respond_to?(candidate, true)
  end
  raise "No platform dispatch target found in #{binding.class} for " +
        "'#{meth.inspect}', tried " + dispatch_candidates(meth).join(', ') unless target
  binding.__send__(target, *args)
end