[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Quirky Curses behavior??

Eric Armstrong

7/21/2006 4:18:00 AM

#!/usr/bin/env ruby

require 'curses'
include Curses

i = 60

# Works
puts (i / 60).to_s

# Works
if (i % 60 == 0) then
puts (i / 60).to_s
end

# Works
addstr (i / 60).to_s

# Error: in `addstr': can't convert Fixnum to string
if (i % 60 == 0) then
addstr (i / 60).to_s
end



2 Answers

Logan Capaldo

7/21/2006 4:30:00 AM

0


On Jul 21, 2006, at 12:18 AM, Eric Armstrong wrote:

> #!/usr/bin/env ruby
>
> require 'curses'
> include Curses
>
> i = 60
>
> # Works
> puts (i / 60).to_s
>
> # Works
> if (i % 60 == 0) then
> puts (i / 60).to_s
> end
>
> # Works
> addstr (i / 60).to_s
>
> # Error: in `addstr': can't convert Fixnum to string
> if (i % 60 == 0) then
> addstr (i / 60).to_s
> end
>
>
>

try running your script like this:

ruby -w <script>

I think you'll notice something interesting is happening when it gets
to that line.





Morton Goldberg

7/21/2006 7:15:00 AM

0

For those reading this thread who don't want to take the time to
follow up on Logan Copaldo's ( (excellent) suggestion, here is some
code contemplate. Parentheses matter.

Regards, Morton

#! /usr/bin/ruby -w

require 'curses'
include Curses

init_screen
begin
i = 60
# Works
addstr((i / 60).to_s)
addstr("\n")
# Works
addstr((i / 60).to_s) if (i % 60 == 0)
addstr("\nPress any key to proceed: ")
refresh
getch
ensure
close_screen
end

On Jul 21, 2006, at 12:30 AM, Logan Capaldo wrote:

> On Jul 21, 2006, at 12:18 AM, Eric Armstrong wrote:
>
>> #!/usr/bin/env ruby
>>
>> require 'curses'
>> include Curses
>>
>> i = 60
>>
>> # Works
>> puts (i / 60).to_s
>>
>> # Works
>> if (i % 60 == 0) then
>> puts (i / 60).to_s
>> end
>>
>> # Works
>> addstr (i / 60).to_s
>>
>> # Error: in `addstr': can't convert Fixnum to string
>> if (i % 60 == 0) then
>> addstr (i / 60).to_s
>> end
>
> try running your script like this:
>
> ruby -w <script>
>
> I think you'll notice something interesting is happening when it
> gets to that line.