From: Kenichi Komiya Date: 2001-01-23T01:44:17+09:00 Subject: [ruby-talk:9722] Re: Name of iterators for trees? Hi, From: "Agnot Tok" Subject: [ruby-talk:9716] Name of iterators for trees? Date: Tue, 23 Jan 2001 00:08:04 +0900 > Hi, > > Iterators is a nice concept and I'm trying to apply the idea to trees. > However, I'm not sure how to name things. Should "each" be a depth-first, > reversed-depth-first or even a breadth-first iterator? Should it be > parameterized so that the user can specify the node-visiting order? Anyone > seen any work/a good design on/for this? Whats a "natural" naming? > > my_tree.each(:DEPTH_FIRST) {|node| ...} > or > my_tree.each_node_depth_first {|node| ...} I think the later is more common. ex. String#each and String#each_byte. There is an alternative way. You may find Okada-yun-Jun's EnumDelegator in RAA useful. quote from the document: # What's enumdelegator? # # Enumdelegator is a library, to add Enumerable capability to a existing # method, which takes block as argument (namely iterator!). # # # In ruby, there are classes, which have several methods named # 'each_*'. for exapmple, String have both 'each_line' and # 'each_byte'. # # In such a class, I have a desire to apply Enumerable methods to # these #methods, but I couldn't. 'each' is a only method, who is # interface for Enumerable. Regards, Komiya.