vimal
2/17/2009 4:38:00 AM
On Feb 16, 7:03 pm, "Alexandru E. Ungur"
<alexan...@globalterrasoft.ro> wrote:
> >>> sender: "vimal" date: "Mon, Feb 16, 2009 at 09:40:02PM +0900" <<<EOQ
> > 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.