Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, November 16, 2008

Use join method to merge Array into string

If you are a Ruby/Ruby on Rails developer.
Some times you need to concatenate/ merge Array elements into String, so its good to use join (Array method).

E.g;
users_id = Array.new
#Add some ids into array, so it becomes,
users_id = [1001,1002,1003,1004,1005]
#Now use need all users ids in to lets say in query so just do,
#users_id.join(",") this will return String type object having users ids
users_id.join(",")
# "1001,1002,1003,1004,1005"