print "\n\n\nArrayOfCreatures\n"
print "================\n\n"
i=0
while i < self.length
print "\n\n"
print i
print ":\n"
print self[i].toString
i=i+1
end
Is this all that’s required to ensure that there’s ever only one
instance of an ArrayOfCreatures? Seems too easy!
Implementing a singleton class by hand is easy too, so you aren’t
getting much savings using the Singleton module–you save yourself from
having to write 4 extra lines of code.
If I have a method with 200 lines of code in it, and I put the method in
its own module Calculations, I can perform the complicated calculation
by writing:
require ‘calculations’
result = my_meth(10, 20, 3.5)
That’s pretty easy too, isn’t it?
On a side note: when you ask questions, you want to make it as easy as
possible for people to answer your questions, right? Posting code
without indentation is bad form because it makes your code harder to
read. Some people won’t even bother with your questions if you can’t be
bothered with posting indented code. In Ruby, the recommended style is
to use 2 spaces for indenting. Your code would look look something like
this:
On a side note: when you ask questions, you want to make it as easy as
possible for people to answer your questions, right? Posting code
without indentation is bad form because it makes your code harder to
read. Some people won’t even bother with your questions if you can’t be
bothered with posting indented code. In Ruby, the recommended style is
to use 2 spaces for indenting. Your code would look look something like
this:
…
list. rb wrote:
Posting code without indentation? wtf?
Yeah, I see the indentation on both the mailing list and the forums in
the OP and the replies, so I don’t understand where this is coming from.
-Justin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.