Page 1 of 1

Ruby constants

Posted: Tue Nov 22, 2016 2:11 pm
by Rocko
Hi,

Stupid question, but still... Any hint on how can I use mathematical constants in ruby?

I want o use 'exp' (natural exponent = 2.71...) or Pi (=3.1415...) in Ruby and looking for a short way to type it in.
I was trying E, math.E, etc but couldn't find a way.
Google didn't help much either...

The only solution I found so far is to define a constant at start of Ruby code, example:

@E=Math.exp(1)

But I guess there is a better way ??

Thanks

Re: Ruby constants

Posted: Tue Nov 22, 2016 2:16 pm
by KG_is_back
Constants of a class can be accessed by :: operator.

Code: Select all

Math::PI
Math::E