On Mar 11, 2006, at 5:13 PM, John M. Gabriele wrote:

> I think this subject might make for a very nice article in
> the faq (maybe to complement
> http://www.rubygarden.org/faq/entry/show/14 ), or else
> possibly could belong at http://www.ruby-doc.org/docs/ .
>
> If it's too much to post on this list, please let me know
> where it might be more appropriate. I'm not asking these
> questions because I'm too lazy to look them up (I will,
> regardless), but rather, I think this might be a useful
> thread.
>
> Anyhow, for someone coming from Python to Ruby looking to
> learn the crucial basic differences in a hurry:
>
>
> - Does Ruby do "everything is a reference to an object"
> like Python does? Or does it do like Perl where a variable
> *is* the object, and if you want a reference you need to
> explicitly take a reference to it?
>
Everything is a reference to an object

>
> - Python is strongly typed (every object has a type, and
> the system doesn't automatically convert between types)
> and dynamically typed (types are figured out at runtime
> as much as possible). Is Ruby strongly or weakly typed?
> Dynamically or statically typed?
>
>
Strong-Dynamic

> - In Python, everything is an object (including classes
> and modules too). Is Ruby that way too?
>
Yes
>
> - Python has the notion of bound and unbound methods
> (so that you can call a method like an instance method,
> or as what looks like a class method if you include
> an instance of its class in the argument list). Then
> it also has class methods and static methods too. Does
> Ruby have bound/unbound methods like this?
>
>
Yeeees.... I think.

a = "Hello"

to_s_from_object = Object.instance_method(:to_s) #=> #<UnboundMethod:  
Object(Kernel)#to_s>

to_s_from_obj_bound = to_s_from_object.bind(a) #=> #<Method:  
String#to_s>
to_s_from_obj_bound.call() #=> "#<String:0x3a6ebc>"

If that's the  sort of thing you mean

> - With Python, strings and tuples are immutable (for
> speed, I believe). Does Ruby have immutables like this,
> or are most object mutable?
>
Strings are mutable, symbols, fixnums, floats and bignums are  
immutable (among others)
For  the most part if it makes sense that something should be  
mutable, it is. I don't think that mutability is ever determined on  
the basis of performance ( except for maybe symbols)

Ruby doesn't have tuples (If these are the same tuples from ML,  
etc.). Its array's are mutable.

>
> - Python has import where it loads and runs the module
> right where it hits that import statement. If the module's
> already been imported, subsequent imports don't do anything
> special. Is ruby like this?
>
>

the method is called "require".

> - Python uses _foo, __bar, and __baz__ underscore notation
> loosely for private references. Does Ruby have similar
> notions of "privacy"?
>

Method visibility can be controlled via the private, public, and  
protected key words. You can always get past these of  course by use  
of #instance_eval for instance.

>
> - Python has the pydoc command that can read docstrings
> right there in your .py file and present them as a man page.
> Can ruby's "ri" command do this too? Or must "rdoc" get
> involved somehow?
>

I don't believe ri can do on the spot parsing and viewing of the docs  
for a given file.

>
> Any other "In Python it's like {this}, but in Ruby you
> do {that}" you can think of would most likely be useful
> here.
>
> Thanks,
> ---John
> -- 
> (remove zeez if demunging email address)
>