Ruby Newbie - array/hash help

W

William Carpin

Given the following code...


my $ds = new DataSources($dbh);
my $data_sources = $ds->getTableNames();

foreach my $table_name (keys %{$data_sources}){
...some code...
}


Is there any effective way to reproduce the above foreach loop in Ruby?
I've been doing research, but I can't make heads or tails of it. Any
assistance would be greatly appreciated.
 
W

William Crawford

William said:
Given the following code...


my $ds = new DataSources($dbh);
my $data_sources = $ds->getTableNames();

foreach my $table_name (keys %{$data_sources}){
...some code...
}


Is there any effective way to reproduce the above foreach loop in Ruby?
I've been doing research, but I can't make heads or tails of it. Any
assistance would be greatly appreciated.

Wouldn't that just be:

data_sources.each_key do |table_name|
puts table_name
end

(I'm not real sure how the whole datasource/tablename thing works in
ruby, but I was assuming datasources was a Hash once you got it.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,211
Messages
2,571,092
Members
47,694
Latest member
digiadvancemarketing

Latest Threads

Top