A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.ruby-lang.org/en/3.4/RubyVM/../BigDecimal.html below:

class BigDecimal - Documentation for Ruby 3.4

class BigDecimal Public Class Methods

Source

def self.json_create(object)
  BigDecimal._load object['b']
end

See as_json.

Public Instance Methods

Source

def as_json(*)
  {
    JSON.create_id => self.class.name,
    'b'            => _dump.force_encoding(Encoding::UTF_8),
  }
end

Methods BigDecimal#as_json and BigDecimal.json_create may be used to serialize and deserialize a BigDecimal object; see Marshal.

Method BigDecimal#as_json serializes self, returning a 2-element hash representing self:

require 'json/add/bigdecimal'
x = BigDecimal(2).as_json             
y = BigDecimal(2.0, 4).as_json        
z = BigDecimal(Complex(2, 0)).as_json 

Method JSON.create deserializes such a hash, returning a BigDecimal object:

BigDecimal.json_create(x) 
BigDecimal.json_create(y) 
BigDecimal.json_create(z) 

Source

def to_json(*args)
  as_json.to_json(*args)
end

Returns a JSON string representing self:

require 'json/add/bigdecimal'
puts BigDecimal(2).to_json
puts BigDecimal(2.0, 4).to_json
puts BigDecimal(Complex(2, 0)).to_json

Output:

{"json_class":"BigDecimal","b":"27:0.2e1"}
{"json_class":"BigDecimal","b":"36:0.2e1"}
{"json_class":"BigDecimal","b":"27:0.2e1"}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4