Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Using XPath to point to the last child node

   1  doc.root.elements["entry[last()]"]

Reference: XPath Syntax [w3schools.com]

iterate through each child association of a active record class


   1  
   2  class ActiveRecord::Base
   3    def each_child
   4      self.class.reflect_on_all_associations.each do |assoc|
   5        case assoc.macro
   6          when :has_many then send(assoc.name).each { |child| yield child }
   7          when :has_one then yield send(assoc.name)
   8        end
   9      end
  10    end
  11  end
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS