Skip to content

Instantly share code, notes, and snippets.

@garybernhardt
Created September 27, 2011 04:02
Show Gist options
  • Save garybernhardt/1244313 to your computer and use it in GitHub Desktop.
Save garybernhardt/1244313 to your computer and use it in GitHub Desktop.
Before/after let comparison
class Delegator
takes :request, :route_path, :resource, :delegate_name
let(:delegate_method) { @resource.record_class.method(method_name) }
let(:method_name) { @delegate_name.split('.').last.to_sym }
def delegate
delegate_method.call(*delegate_args)
end
def delegate_args
inference_sources = InferenceSources.new(@request,
@route_path,
@request.path_info).sources
InfersArgs.new(delegate_method, inference_sources).args
end
end
class Delegator
def initialize(request, route_path, resource, delegate_name)
@request = request
@route_path = route_path
@resource = resource
@delegate_name = delegate_name
end
def delegate
delegate_method.call(*delegate_args)
end
def delegate_args
inference_sources = InferenceSources.new(@request,
@route_path,
@request.path_info).sources
InfersArgs.new(delegate_method, inference_sources).args
end
def delegate_method
@resource.record_class.method(method_name)
end
def method_name
@delegate_name.split('.').last.to_sym
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment