Re: The beauty of Ruby through examples
- From: Regis d'Aubarede <regis.aubarede@xxxxxxxxx>
- Date: Thu, 30 Sep 2010 09:48:50 -0500
def printTree(tree,indent)
if (Array === tree)
tree.map { |child| printTree(child,indent+"| ") }
else
puts(indent.gsub(/\s+$/,"--")+tree.to_s)
end
end
printTree([1,2,[11,22,[111,222,333,444],33],3,4],"")
this give :
|--1
|--2
| |--11
| |--22
| | |--111
| | |--222
| | |--333
| | |--444
| |--33
|--3
|--4
--
Posted via http://www.ruby-forum.com/.
.
- References:
- The beauty of Ruby through examples
- From: Adriano Ferreira
- The beauty of Ruby through examples
- Prev by Date: Re: GetoptLong usage
- Next by Date: Re: Seeking sponsors to fly me to RubyConf
- Previous by thread: Re: The beauty of Ruby through examples
- Next by thread: Module design acceptable practices questions..
- Index(es):