Bug #7305 ยป ruby_bigdecimal_docs.patch
| ext/bigdecimal/bigdecimal.c | ||
|---|---|---|
|
return INT2FIX(hash);
|
||
|
}
|
||
|
/*
|
||
|
* call-seq: _dump
|
||
|
*
|
||
|
* Method used to provide marshalling support. See the Marshal module.
|
||
|
*
|
||
|
* inf = BigDecimal.new('Infinity')
|
||
|
* => #<BigDecimal:1e16fa8,'Infinity',9(9)>
|
||
|
* BigDecimal._load(inf._dump)
|
||
|
* => #<BigDecimal:1df8dc8,'Infinity',9(9)>
|
||
|
*
|
||
|
*/
|
||
|
static VALUE
|
||
|
BigDecimal_dump(int argc, VALUE *argv, VALUE self)
|
||
|
{
|
||
| ... | ... | |
|
return self;
|
||
|
}
|
||
|
/* call-seq:
|
||
|
/*
|
||
|
* Document-method: BigDecimal#add
|
||
|
* Document-method: BigDecimal#+
|
||
|
*
|
||
|
* call-seq:
|
||
|
* add(value, digits)
|
||
|
*
|
||
|
* Add the specified value.
|
||
| ... | ... | |
|
return ToValue(c);
|
||
|
}
|
||
|
/* call-seq:
|
||
|
* mult(value, digits)
|
||
|
/*
|
||
|
* Document-method: BigDecimal#mult
|
||
|
*
|
||
|
* call-seq: mult(value, digits)
|
||
|
*
|
||
|
* Multiply by the specified value.
|
||
|
*
|
||
| ... | ... | |
|
return self;
|
||
|
}
|
||
|
/* :nodoc:
|
||
|
*
|
||
|
* private method to clone to clone the provided BigDecimal +other+
|
||
|
*/
|
||
|
static VALUE
|
||
|
BigDecimal_initialize_copy(VALUE self, VALUE other)
|
||
|
{
|
||
| ... | ... | |
|
return INT2FIX(s);
|
||
|
}
|
||
|
/* call-seq:
|
||
|
* BigDecimal.save_exception_mode { ... }
|
||
|
/*
|
||
|
* call-seq: BigDecimal.save_exception_mode { ... }
|
||
|
*
|
||
|
* Excecute the provided block, but preserve the exception mode
|
||
|
*
|
||
|
* BigDecimal.save_exception_mode do
|
||
|
* BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
|
||
|
* BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
|
||
|
*
|
||
|
* BigDecimal.new(BigDecimal('Infinity'))
|
||
|
* BigDecimal.new(BigDecimal('-Infinity'))
|
||
|
* BigDecimal(BigDecimal.new('NaN'))
|
||
|
* end
|
||
|
*
|
||
|
* For use with the BigDecimal::EXCEPTION_*
|
||
|
* See BigDecimal.mode
|
||
|
*/
|
||
|
static VALUE
|
||
|
BigDecimal_save_exception_mode(VALUE self)
|
||
| ... | ... | |
|
return ret;
|
||
|
}
|
||
|
/* call-seq:
|
||
|
* BigDecimal.save_rounding_mode { ... }
|
||
|
/*
|
||
|
* call-seq: BigDecimal.save_rounding_mode { ... }
|
||
|
*
|
||
|
* Excecute the provided block, but preserve the rounding mode
|
||
|
*
|
||
|
* BigDecimal.save_exception_mode do
|
||
|
* BigDecimal.mode(BigDecimal::ROUND_MODE, :up)
|
||
|
* puts BigDecimal.mode(BigDecimal::ROUND_MODE)
|
||
|
* end
|
||
|
*
|
||
|
* For use with the BigDecimal::ROUND_*
|
||
|
* See BigDecimal.mode
|
||
|
*/
|
||
|
static VALUE
|
||
|
BigDecimal_save_rounding_mode(VALUE self)
|
||
| ... | ... | |
|
return ret;
|
||
|
}
|
||
|
/* call-seq:
|
||
|
* BigDecimal.save_limit { ... }
|
||
|
/*
|
||
|
* call-seq: BigDecimal.save_limit { ... }
|
||
|
*
|
||
|
* Excecute the provided block, but preserve the precision limit
|
||
|
*
|
||
|
* BigDecimal.limit(100)
|
||
|
* puts BigDecimal.limit
|
||
|
* BigDecimal.save_limit do
|
||
|
* BigDecimal.limit(200)
|
||
|
* puts BigDecimal.limit
|
||
|
* end
|
||
|
* puts BigDecimal.limit
|
||
|
*
|
||
|
*/
|
||
|
static VALUE
|
||
|
BigDecimal_save_limit(VALUE self)
|
||
| ext/json/lib/json/add/bigdecimal.rb | ||
|---|---|---|
|
defined?(::BigDecimal) or require 'bigdecimal'
|
||
|
class BigDecimal
|
||
|
# Import a JSON Marshalled object.
|
||
|
#
|
||
|
# method used for JSON marshalling support.
|
||
|
def self.json_create(object)
|
||
|
BigDecimal._load object['b']
|
||
|
end
|
||
|
# Marshal the object to JSON.
|
||
|
#
|
||
|
# method used for JSON marshalling support.
|
||
|
def as_json(*)
|
||
|
{
|
||
|
JSON.create_id => self.class.name,
|
||
| ... | ... | |
|
}
|
||
|
end
|
||
|
# return the JSON value
|
||
|
def to_json(*)
|
||
|
as_json.to_json
|
||
|
end
|
||