开发者

Refactor my ruby snippet so it doesn't look like C anymore: method(method(param))

开发者 https://www.devze.com 2023-02-13 01:27 出处:网络
开发者_开发技巧I have a class which uses a connection object to send the request data created by a request_builder object.

开发者_开发技巧I have a class which uses a connection object to send the request data created by a request_builder object.

The code looks like this: connection.send_request(request_builder.build_request(customer))

This in turn is called by build_report(customer, connection.send_request(request_builder.build_request(customer)))

Ugly! Any ideas on how to make it more expressive? Usually in ruby and OOP we chain objects like this: "string".make_it_bigger.flash_it.send


It's code, that how it looks. But you can make yourself a favour by not trying to cram everything together on one line:

request = request_builder.build_request(customer)
response = connection.send_request(request)
report = build_report(customer, response)

if you told us more about your code base we might be able to suggest something else, but you don't give us very much to go on. What does the request_builder object do? Does connection.send_request(...) return a response? Why does a report need a customer and a response (assuming that's what is returned by connection.send_request(...)), and so on.


build_report(customer, request_builder.build_request(customer).send_over(connection))
0

精彩评论

暂无评论...
验证码 换一张
取 消