Hello there!
I’m new to Ruby and my first impressions are really good: after some
experience with both Perl and Python, the clean OO-ness of Ruby has been
exciting, not to talk about its “no surprises” approach.
My first questions are of various kind, please apologize me for mixing
them in a single message:
-
on my monster PC (a glorious 200mhz Pentium box with W98…), Ruby’s
startup time is about 1 second (e.g., ruby -e “p ‘hello world’” takes 1
second) Isn’t it too much?
Using IRB is even worse: it takes about 2/3 seconds to show the first
prompt, and about 0.5 seconds to process every line. Is this normal? Is
it time for me to think to a Pentium II?
I’m using Ruby 1.6.7, installed from ruby-1.6.7-i586-mswin32.zip (sorry,
I don’t remember the exact version of the executable I downloaded, but
it’s the one which does not require Cygwin or other support environments) -
after browsing the Pragmatic Programmer’s Guide, I did some tests with
Module.constants and Module#constants. Now I really don’t understand the
following:
module M
Konst1=1
endM.constants
[‘Konst1’]
class C
Konst2=1
endC.constants
[“Konst2”, “DATA”, “FALSE”, “ARGV”, …]
Why the different behaviour? I mean, why #constants returns just a
module’s own constans, and a class’ own and inherited constants?
There is also the fact that:
M::DATA
#<File:0x257cc5c>
C::DATA
#<File:0x257cc5c>
Since DATA is accessible through M (as well as all other consts),
shouldn’t M.constants include it (together with all other consts)?
I’ve read about the C.constants-C.superclass.constants trick, my problem
is not finding a way to discover C’s own constants, I just would like to
understand #constants has a different behaviour when it is applied to a
module or a class.
2bis) To understand when Module.constants and Module#constants are
called, I used:
class Module
alias oldc constants
def constants
puts “constants”
oldc
end
class <<self
alias oldmc constants
def constants
puts “Module.constants”
oldmc
end
end
end
Is this right? is is the right way to do it?
- If I want to use a script to persistently (i.e., after Ruby’s
exit) change the working dir, how do I do? Neither
ruby -e “system(‘cd \’); puts Dir.getwd”
nor
ruby -e “Dir.chdir(‘\’); puts Dir.getwd”
seem to work
- Comparing Ruby with the Pythonesque “batteries included” approach
wasn’t very exciting… At times I think that Python (ActiveState) distro
is overloaded, but all in all I prefer too many (optional) features than
too few. Is there a reference Ruby library? Are there distros supporting
it?
That’s all for now. My compliments to Matz, I really like the language,
its simplicity and its object orientation, definitely one step above the
competition.
And thank you in advance for your help.
Andrea (which, FYI, is a male name here in Italy )