Math functions and SU7
-
I just noticed while testing some of my SU6 plugins that there is a problem with the inbuilt Ruby Math functions. If I type the following into the Ruby console I get an error:
tan(20)
Error: #<NoMethodError: (eval):56: undefined method `tan' for main:Object>
(eval):56
Math::tan(20)
2.23716094422474tan(20) works with SU6
Can someone confirn this
-
Hi Bill,
This isn't unexpected behavior. tan is a method of the Math module, and you need to prefix it with the module name in order to call it. If you type in the Ruby Console:
include Math
then simply writing tan(20) will work. To ensure you are using Math::tan, and not someone else's 'tan' method, you probably want to always write it as 'Math::tan'
Here is a chapter which discusses modules as namespaces:
http://www.rubycentral.com/pickaxe/tut_modules.html
It could be that there is a plugin in your version 6 folder that uses 'include Math' and so 'tan' is available in your version 6 Ruby Console.
-
Without "include Math" statement (directly from Ruby's console or from any autoloaded plugin), it does not work here. With "Math included", it works fine.
Marcio
Advertisement