Forum: Ruby append .cvs behind an array value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ef876fc6e1baa12cef2c381ea6feabbe?d=identicon&s=25 Martin Sharon (martinh)
on 2009-04-27 06:22
I want to add ".cvs" at the end of a name,and use the following
sentenses:


namelist.each do |name|
  name = name +'.cvs'
end

but error message is :

test2.rb:43:in `+': can't convert String into Array (TypeError)
        from test2.rb:43
        from test2.rb:39:in `each'
        from test2.rb:39

What's wrong with it? how to fix it?

thanks!
289cf19aa581c445915c072bf45c5e25?d=identicon&s=25 Todd Benson (Guest)
on 2009-04-27 06:42
(Received via mailing list)
On Sun, Apr 26, 2009 at 11:22 PM, Martin Sharon <huangshuo.9@gmail.com>
wrote:
> I want to add ".cvs" at the end of a name,and use the following
> sentenses:
>
>
> namelist.each do |name|

puts name.class
#this will tell you what your name objects are

>  name = name +'.cvs'
> end
>
> but error message is :
>
> test2.rb:43:in `+': can't convert String into Array (TypeError)
>        from test2.rb:43
>        from test2.rb:39:in `each'
>        from test2.rb:39


If your objects in namelist are enumerable objects, then you must
further take it apart.
Ef876fc6e1baa12cef2c381ea6feabbe?d=identicon&s=25 Martin Sharon (martinh)
on 2009-04-27 06:49
It's an arry object.


>> end
>>
>> but error message is :
>>
>> test2.rb:43:in `+': can't convert String into Array (TypeError)
>>        from test2.rb:43
>>        from test2.rb:39:in `each'
>>        from test2.rb:39
>
>
> If your objects in namelist are enumerable objects, then you must
> further take it apart.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-04-27 07:02
Martin Sharon wrote:
> It's an arry object.
>

..and how do you step through an array?
Ef876fc6e1baa12cef2c381ea6feabbe?d=identicon&s=25 Martin Sharon (martinh)
on 2009-04-27 07:08
arrayname.each do |name|
  puts name

end





7stud -- wrote:
> Martin Sharon wrote:
>> It's an arry object.
>>
>
> ..and how do you step through an array?
This topic is locked and can not be replied to.