Friday, 15 May 2015

ruby - Pass an arithmetic operator as parameter to rails method? -


Is it possible to pass a mathematical operator (*, +, -, /) as a parameter of the Ruby method? I have performed it in C ++ What is the same rail?

  Calculates the DF (operator) 1254 operator 34 finally (+)    

to:

  Calculate the DRAF (OP) 1254.send (op, 34) Calculates the end (: +)   

It works for any method, including defined arithmetic operators. Note that you need to send the method name as a symbol or string.

No comments:

Post a Comment