Peter Szinek wrote: > Hello, > > I have two very similar code snippets in two different methods, and I am > absolutely sure there is some nice way to DRY them in Ruby... I am still > a noob when comes to Ruby idioms so I'd appreciate some help ;-) If you had this: def ancestors element ... while element.class != Hpricot::Doc do path.push element element = element.parent end path end > ... > while element.class != Hpricot::Doc do > path.push element.name > element = element.parent > end > ... would become: ancestors(element).map{|a|a.name} > and > ... > while element.class != Hpricot::Doc do > path.push element > element = element.parent > end > ... would become: ancestors(element) > i.e. in the first snippet I am pushing element's names, and in the > latter the elements themselves. > > Thanks, > Peter cheers Simon