Quirky Curses behavior??

E

Eric Armstrong

#!/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
 
L

Logan Capaldo

#!/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.
 
M

Morton Goldberg

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
 

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
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top