From: vimal Date: 2009-02-17T13:40:03+09:00 Subject: Re: Hash :: Recursive traversing and stripping the values On Feb 16, 7:03 pm, "Alexandru E. Ungur" wrote: > >>> sender: "vimal" date: "Mon, Feb 16, 2009 at 09:40:02PM +0900" << > So is there any other way to carry out thisstripping > > functionality thoughout thehash(if nested too)!!! > >>>EOQ > > Of course there is: > >         elsif v.class ==Hash >           strip_hash_values(hash) >         end > > should actually be: > >         elsif v.class ==Hash >           strip_hash_values(v) >         end > > Additionally, you could 'cheat' and use "case" (no more need to check > the type/class manually): This is what an user expects to learn(some additional tips) and master a scripting lang > > def strip_hash_values(hash) >  hash.each do |k, v|       >         case v >     when String >       v.strip! >     when Array >       v.each {|vv| vv.strip!} >     whenHash >       strip_hash_values(v) >         end >   end > end > > Cheers, > Alex Thanks for all your suggestions I now figure it how.