[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Code Block Error

Drew Olson

9/20/2006 7:25:00 PM

The following code works fine:

counter = 0;
semi_common_tbls.keys.each do |set|
semi_common_tbls[set].each do |table|
outfile << ["CommonTables"+counter.to_s,table]
end
end

However, when I change it like so:

counter = 0;
semi_common_tbls.keys.each do |set|
counter++
semi_common_tbls[set].each do |table|
outfile << ["CommonTables"+counter.to_s,table]
end
end

I get the following error:
tablebuildv2.rb:46: undefined method `+@' for ["table1", "table5"]:Array
(NoMethodError)
from tablebuildv2.rb:42:in `each'
from tablebuildv2.rb:42

What gives?

Thanks,
Drew

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

3 Answers

Drew Olson

9/20/2006 7:28:00 PM

0

Well, it seems you can't use ++ as in Java, changed to +=1.

Thanks,
Drew

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

James Gray

9/20/2006 7:28:00 PM

0

On Sep 20, 2006, at 2:24 PM, Drew Olson wrote:

> However, when I change it like so:
>
> counter = 0;
> semi_common_tbls.keys.each do |set|
> counter++

Ruby doesn't have a ++ operator. Try:

counter += 1

> semi_common_tbls[set].each do |table|
> outfile << ["CommonTables"+counter.to_s,table]
> end
> end
>
> I get the following error:
> tablebuildv2.rb:46: undefined method `+@' for ["table1",
> "table5"]:Array
> (NoMethodError)
> from tablebuildv2.rb:42:in `each'
> from tablebuildv2.rb:42

James Edward Gray II

Chris Hulan

9/20/2006 7:33:00 PM

0

Drew Olson wrote:

> However, when I change it like so:
>
> counter = 0;
> semi_common_tbls.keys.each do |set|
> counter++

'++' is not a Ruby operator, it doesn't have any of the
unary increment/decrement operators.

Closest is
counter += 1

cheers