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.
精彩评论