[Rails] Re: Determine if a value is an instance of String , or Array

Tore Darell toredarell at gmail.com
Sat Mar 4 19:10:02 GMT 2006


hash.each{|k,v|
  v.capitalize! if v.is_a? String
}

Or use Rick's "duck typing" approach.


oo00oo wrote:
> each loop inside a mixed hash
> I need to determine if the value is an instance of String
> How ?
> 
> hash.each do |k,v|
>     if v ( instance of ) String
>        hash[ k ] = v.capitalize
>     enf
> end

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list