C
Colin Summers
I worked a lot in tcl, and this is my first day of trying something in
Ruby. Second, maybe.
class Thread
def initialize number
@number = number ; #
@replies = 0 ;
end ; # initialize
def filename
dirname = "./data/" ; # the directory where the files are kept
filename = dirname + @number.toS + "-" + @replies.toS + ".html"
return filename
end ; # filename
end ; # Thread definition
puts "Finished definitions."
thread[1727] = Thread.new 1727
puts "The filename would be: "
puts thread[1727].filename
Of course, that doesn't work. It is unhappy with the code to create
the filename, since .toS is not a method for fixnum (which apparently
is what @number is, but I never TOLD it that was a fixnum).
And I can't seem to define "thread" to be an array of class Thread
objects. I want to refer to thread[1702] and thread[291] and hop
around like that.
(And, perhaps a more advanced question, right now I am making the
thread number part of the object, ultimately for a gorgeous bit of
code it seems like the object should just know the index of the array
instead, so if I ask thread[32] what it's filename is it would know
that it is thread #32. Can it do that?)
Thanks. I know it's a basic question. It's been a decade since I
learned a new language. I gotta get out more.
--Colin
Ruby. Second, maybe.
class Thread
def initialize number
@number = number ; #
@replies = 0 ;
end ; # initialize
def filename
dirname = "./data/" ; # the directory where the files are kept
filename = dirname + @number.toS + "-" + @replies.toS + ".html"
return filename
end ; # filename
end ; # Thread definition
puts "Finished definitions."
thread[1727] = Thread.new 1727
puts "The filename would be: "
puts thread[1727].filename
Of course, that doesn't work. It is unhappy with the code to create
the filename, since .toS is not a method for fixnum (which apparently
is what @number is, but I never TOLD it that was a fixnum).
And I can't seem to define "thread" to be an array of class Thread
objects. I want to refer to thread[1702] and thread[291] and hop
around like that.
(And, perhaps a more advanced question, right now I am making the
thread number part of the object, ultimately for a gorgeous bit of
code it seems like the object should just know the index of the array
instead, so if I ask thread[32] what it's filename is it would know
that it is thread #32. Can it do that?)
Thanks. I know it's a basic question. It's been a decade since I
learned a new language. I gotta get out more.
--Colin