开发者

Beginner refactor question

I would like to know the best or most correct way to refactor this.

series = Hash.new
seri开发者_StackOverflowes[:series_id] = doc.xpath("Data/Series/id").inner_text if not doc.xpath("Data/Series/id").nil?


series = { :series_id => doc.xpath("Data/Series/id").try(:inner_text) }


Something like

series = Hash.new
id_element = doc.xpath("Data/Series/id")
series[:series_id] =  id_element.inner_text unless id_element.nil?


I think the most revolutionary refactoring would be using xml to object mapping library like happymapper and leave all this dirty implementation details under the hood.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜