From: Jim Weirich Date: 2004-08-04T03:27:36+09:00 Subject: Re: __call__ equivalent? Kevin Howe said: > Does Ruby have an equivalent of Python's __call__ method? Yes and no. If you are asking: Can you define a call operator in a class so that instances of that can pretend to be called with a function-like syntax? Then the answer is no. Mainly because there is no "call" operator in Ruby. If you are asking: Can you define objects that act like functions (ie. functors). Then then answer is yes. Proc and Continuations are objects that act like functions. To call them, you send them a "call" message with the appropriate arguments. To define your own callable object, just implement the "call" method. Also the "[]" operator is often an alias for call. -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)