From: Stefan Lang Date: 2008-11-15T20:06:50+09:00 Subject: Re: how to call operator as function 2008/11/15 Vladimir Fekete : > Hi *, > > could you help me please ? I'm trying to write a code where I could have > operators' functions as values of hash and executing them in way like this > (formal code): > > #============================= > operators = { "+" => Fixnum.+, > "-" => Fixnum.-, > "++" => Myclass.++} > > op = "+" > > result = operators[op](left,right) if left.class==Fixnum and right.class==Fixnum > #============================ > > is it possible ? Thanks, Use send, if all operators are binary: left.send(:+, right) left.send(:-, right) etc. Stefan