From: Vincent Fourmond Date: 2007-01-10T08:31:36+09:00 Subject: Re: Why is there a seperate Math class? Daniel Finnie wrote: > Why does everything have to be Math.(num)? Isn't num.func more > object oriented-ish? > > For example: >>> (Math.methods - Object.methods).select {|x| Math.method(x).arity == > 1}.each do |x| > ?> Numeric.class_eval { ?> define_method(x.to_sym) { > Math.send(x.to_sym, self) } >> } >>> end > => ["tan", "frexp", "sinh", "exp", "acos", "tanh", "log", "asin", > "acosh", "cos", "log10", "atan", "erf", "asinh", "sin", "sqrt", "cosh", > "erfc", "atanh"] >>> *5.sqrt* > => 2.23606797749979 >>> *Math.sqrt(5)* > => 2.23606797749979 >>> I have to say I'm very happy with that sort of things, as in a program of my own, (plotting scientific data), the user just can say ctioga --math 'sin(x)' to plot the sine of x. It would be confusing for a non rubyist to run ctioga --math 'x.sin' Wouldn't it ? Don't forget in this particular case, syntax can have impact on non-programming users... Cheers ! Vince -- Vincent Fourmond, PhD student http://vincent.fourmond.neuf.fr/