Search code examples
rubybigdecimal

How to parse ruby BigDecimal inspect?


In the following code:

x = BigDecimal(10)
s = x.inspect # "#<BigDecimal:6fe4790,'0.1E2',9(36)>"

Is there a way to parse s and get the original value ? The reason is that I have some text files with BigDecimal written in them using inspect, and I need to parse these values.


Solution

  • "#<BigDecimal:6fe4790,'0.1E2',9(36)>"[/(?<=').+(?=')/]
    # => "0.1E2"