module RailwayOperation::Surround
Public Instance Methods
wrap(*surrounds, arguments: [], &body)
click to toggle source
# File lib/railway_operation/surround.rb, line 5 def wrap(*surrounds, arguments: [], &body) @body = body @arguments = arguments execute(surrounds) end
Private Instance Methods
execute(surrounds)
click to toggle source
# File lib/railway_operation/surround.rb, line 14 def execute(surrounds) surround, *rest = surrounds result = nil send_surround(surround, *@arguments) do result = if rest.empty? @body.call else execute(rest) end end result end
send_surround(surround, *args) { || ... }
click to toggle source
# File lib/railway_operation/surround.rb, line 29 def send_surround(surround, *args) case surround when Symbol # wrap(with: :my_method) send(surround, *args) { yield } when Array # wrap(with: [MyClass, :method]) surround[0].send(surround[1], *args) { yield } when Proc # wrap(with: -> { ... }) surround.call(-> { yield }, *args) else # no wrap yield(*args) end end