From: Sam Smoot Date: 2007-12-11T21:00:03+09:00 Subject: Re: Dynamically generate a symbol name On Dec 11, 5:51 am, Max Williams wrote: > I'm sure this is simple but i can't work out the syntax - if i want to > use a bunch of symbols that are named :object0, :object2 ... :object9, > how can i do something like > > 10.times do |n| > do_something_with(:object#{n} => "foo") > end > > ie, do the same thing with but pass through a differently named symbol > each time? > > thanks > max > -- > Posted viahttp://www.ruby-forum.com/. :"object#{n}" is the syntax. Or just "object#{n}".to_sym. I would avoid doing this though. Symbols aren't meant to represent infinite variations. They're stored in a Hash internally, so the more symbols you add, the slower they get. So a small finite set of symbols is good. To represent environments, or database names, or even columns. Representing filenames as symbols, or user_ids, or something similarly large and near as infinite as makes no difference is a bad idea IMO. At least if I understand the mechanics of Symbol storage. And I may not. ;-)