Some More Equivalencies

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


Table B.1 is a listing of a few more functions, operators, and other items. The Python entity is in the left column; in the right column you will find the rough Ruby equivalent and/or some pertinent comments.

Table B.1. Functions, Operators, and Other Items
Python Ruby
__bases__ ancestors
__getattr__ method_missing
__getitem__, __getslice__ []
__import__ load, require (redefinable)
__setitem__ []=
__class__ class, type
__methods__, __members__, __dict__ (various methods)
apply(f,args) Functions are not objects; refer to proc objects: proc.call(args) or obj.send(:method,args)
callable respond_to?
cmp() <=>
complex() require "complex" (etc.)
filter() find_all
isinstance kind_of?
issubclass ancestors.include?
len() size, length
list() to_a
__init__ initialize
__lt__, etc. <, etc.
__hash__ Object#hash
__add__, etc. +, etc.
sys.modules $"
sys.path $LOAD_PATH, $:
sys.argv ARGV, $*
sys.stdin $stdin
os.environ ENV
if name == '__main__' if $0 == __FILE__
if x in y: if y.include? x
if:/elif:/else: if/elsif/else/end
for i in x: for i in x/end
break/continue break/next/redo



   

 

 



The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net