Ruby constants

For general discussion related FlowStone
Post Reply
Rocko
Posts: 186
Joined: Tue May 15, 2012 12:42 pm

Ruby constants

Post 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
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Ruby constants

Post by KG_is_back »

Constants of a class can be accessed by :: operator.

Code: Select all

Math::PI
Math::E

Post Reply