Fixnum assignment undefined? Is it a bug, or blindness?

In the routine:
def calcRowSals(init, step)
result = Array.new(@colHeads.size - 1, 0)
val = (init * 1000).to_i
for i in 0…result.size
result[i] = (val / 10).to_f / 100.
val = (val * @step) #<<== Here is the error
val = val.to_i
end
result
end # calcRowSals

I get the error message:
paySchedHtml.rb:24:in calcRowSals': undefined methodval=’ for
100:Fixnum (NoMethodError)
from paySchedHtml.rb:22:in each' from paySchedHtml.rb:22:incalcRowSals’
from paySchedHtml.rb:204:in to_html' from paySchedHtml.rb:203:ineach’
from paySchedHtml.rb:203:in `to_html’
from paySchedHtml.rb:215

I am running ruby173-6.exe (to identify the Pragmatic Programmers
installer), also know as ruby 1.7.3 (2002-10-12) [i386-mswin32]
The OS is Win98.

Does anyone know what I’m doing wrong here? I don’t have a clue.

···


– Charles Hixson
Gnu software that is free,
The best is yet to be.

Charles Hixson charleshixsn@earthlink.net writes:

In the routine:
def calcRowSals(init, step)
result = Array.new(@colHeads.size - 1, 0)
val = (init * 1000).to_i
for i in 0…result.size
result[i] = (val / 10).to_f / 100.
^— try putting
a zero after the
‘.’ Ruby’s
looking at this
and the next line
as 100.val = …

···
 val	=	(val * @step)	#<<== Here is the error

Charles Hixson wrote:

       result[i]    =       (val / 10).to_f / 100.

No, the error is here =================================^

       val  =       (val * @step)   #<<== Here is the error

You’re calling 100.val=(val*@step)

It says so right there in the code :slight_smile:

Decimal points should always be followed by a digit.

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

Hi,

This is related to Item 14 in the “Things That Newcomers to Ruby Should
Know”:

http://www.glue.umd.edu/~billtj/ruby.html#dot

I guess that although Ruby syntax is in some sense “line based”, a lot of
things can make Ruby continues to the next line, if the interpreter thinks
that the current line is “unfinished”.

Regards,

Bill

···

Charles Hixson charleshixsn@earthlink.net wrote:

 result[i]	=	(val / 10).to_f / 100.
 val	=	(val * @step)	#<<== Here is the error

William Djaja Tjokroaminata wrote:

 result[i]	=	(val / 10).to_f / 100.
 val	=	(val * @step)	#<<== Here is the error

Hi,

This is related to Item 14 in the “Things That Newcomers to Ruby Should
Know”:

http://www.glue.umd.edu/~billtj/ruby.html#dot

I guess that although Ruby syntax is in some sense “line based”, a lot of
things can make Ruby continues to the next line, if the interpreter thinks
that the current line is “unfinished”.

Regards,

Bill

That doesn’t seem to be what’s going on (though it seemed like a good
guess, until I fully parenthesized it. The current re-write is:
r = ((val / 10).to_f )
result[i] = r / 100. ; <<== The error is here
val = (val * @step)
which produces the error message:
C:/Docs/PayScale/rb/paySchedHtml.rb:24: syntax error

Using parentheses instead of a semicolon doesn’t help.

···

Charles Hixson charleshixsn@earthlink.net wrote:


– Charles Hixson
Gnu software that is free,
The best is yet to be.

Hi Charles,

I think it is still a similar thing. When Ruby parses “100.”, it expects
something (a method name) to be sent to the object 100. But because it is
followed by a “;” which signifies the terminating of the current
statement, Ruby complains. (Although probably some message like “missing
method name” would be clearer than simply “syntax error”, I don’t know too
much about the exact internal details and algorithms of the Ruby
parser; so probably “missing method name” is incorrect from Ruby grammar
point of view.)

Regards,

Bill

···

Charles Hixson charleshixsn@earthlink.net wrote:

That doesn’t seem to be what’s going on (though it seemed like a good
guess, until I fully parenthesized it. The current re-write is:
r = ((val / 10).to_f )
result[i] = r / 100. ; <<== The error is here
val = (val * @step)
which produces the error message:
C:/Docs/PayScale/rb/paySchedHtml.rb:24: syntax error

Using parentheses instead of a semicolon doesn’t help.

Hello Charles,

Tuesday, October 29, 2002, 6:54:22 PM, you wrote:

        result[i]    =    r / 100. ;        <<==  The error is here
        val    =    (val * @step)

which produces the error message:
C:/Docs/PayScale/rb/paySchedHtml.rb:24: syntax error

Using parentheses instead of a semicolon doesn’t help.

try:
result[i] = r / 100.0

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hi,

Seems to work here (ruby 1.7.3), with “result[i] = r / 100.0” no need for the
semicolon, but an extra 0 after the dot.

Francois

···

On Tuesday 29 October 2002 22:54, Charles Hixson wrote:

William Djaja Tjokroaminata wrote:

Charles Hixson charleshixsn@earthlink.net wrote:

 result[i]	=	(val / 10).to_f / 100.
 val	=	(val * @step)	#<<== Here is the error

Hi,

This is related to Item 14 in the “Things That Newcomers to Ruby Should
Know”:

http://www.glue.umd.edu/~billtj/ruby.html#dot

I guess that although Ruby syntax is in some sense “line based”, a lot of
things can make Ruby continues to the next line, if the interpreter thinks
that the current line is “unfinished”.

Regards,

Bill

That doesn’t seem to be what’s going on (though it seemed like a good
guess, until I fully parenthesized it. The current re-write is:
r = ((val / 10).to_f )
result[i] = r / 100. ; <<== The error is here
val = (val * @step)
which produces the error message:
C:/Docs/PayScale/rb/paySchedHtml.rb:24: syntax error

Using parentheses instead of a semicolon doesn’t help.

Francois GORET wrote:

···

On Tuesday 29 October 2002 22:54, Charles Hixson wrote:

William Djaja Tjokroaminata wrote:

Charles Hixson charleshixsn@earthlink.net wrote:

 result[i]	=	(val / 10).to_f / 100.
 val	=	(val * @step)	#<<== Here is the error

Hi,

This is related to Item 14 in the “Things That Newcomers to Ruby Should
Know”:

http://www.glue.umd.edu/~billtj/ruby.html#dot

I guess that although Ruby syntax is in some sense “line based”, a lot of
things can make Ruby continues to the next line, if the interpreter thinks
that the current line is “unfinished”.

Regards,

Bill

That doesn’t seem to be what’s going on (though it seemed like a good
guess, until I fully parenthesized it. The current re-write is:
r = ((val / 10).to_f )
result[i] = r / 100. ; <<== The error is here
val = (val * @step)
which produces the error message:
C:/Docs/PayScale/rb/paySchedHtml.rb:24: syntax error

Using parentheses instead of a semicolon doesn’t help.

Hi,

Seems to work here (ruby 1.7.3), with “result[i] = r / 100.0” no need for the
semicolon, but an extra 0 after the dot.

Francois

OK. That explains it. I finally just got around it by multiplying
instead of dividing, but it’s good to know what the problem was.


– Charles Hixson
Gnu software that is free,
The best is yet to be.