{&: rooto:"YARD::CodeObjects::RootObject:@childrenIC:&YARD::CodeObjects::CodeObjectList[o:#YARD::CodeObjects::ClassObject;IC;["o:$YARD::CodeObjects::MethodObject:@module_functionF:@scope:
instance:@visibility:public:
@pathI"Rational#numerator:EF:@parameters[ :@files[[I"rational.c;Tiq:@current_file_has_commentsT:
@name:numerator:@source_type0:
@tags[ :@docstrings{ :@docstringIC:YARD::Docstring"Returns the numerator.
Rational(7).numerator #=> 7
Rational(7, 1).numerator #=> 7
Rational(9, -4).numerator #=> -9
Rational(-2, -10).numerator #=> 1
;T;[o:YARD::Tags::OverloadTag
:@tag_nameI"
overload;F:
@text0;;:@types0:@signatureI"numerator;T;IC;" ;T;[o:YARD::Tags::Tag
;I"return;F;I" ;T;0;[I"Integer;T:@object@
:@ref_tags[ : @allI"@return [Integer];T:@unresolved_reference0;"@
:
@summary0:@hash_flagF:@ref_tag_recurse_counti ;[ ;"@
;#[ ;$I"Returns the numerator.
Rational(7).numerator #=> 7
Rational(7, 1).numerator #=> 7
Rational(9, -4).numerator #=> -9
Rational(-2, -10).numerator #=> 1
@overload numerator
@return [Integer];T;%0;"@
;'F:@line_rangeo:
Range: exclT:
beginif:endio:@namespace@; I"static VALUE;T:@sourceI"Zstatic VALUE
nurat_numerator(VALUE self)
{
get_dat1(self);
return dat->num;
};T:@explicitTo;
;F;;
;;;I"Rational#denominator;F;[ ;[[@i;T;:denominator;0;[ ;{ ;IC;"Returns the denominator (always positive).
Rational(7).denominator #=> 1
Rational(7, 1).denominator #=> 1
Rational(9, -4).denominator #=> 4
Rational(-2, -10).denominator #=> 5
rat.numerator.gcd(rat.denominator) #=> 1
;T;[o;
;I"
overload;F;0;;1;0; I"denominator;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Integer;T;"@&;#[ ;$I"@return [Integer];T;%0;"@&;&0;'F;(i ;[ ;"@&;#[ ;$I"8Returns the denominator (always positive).
Rational(7).denominator #=> 1
Rational(7, 1).denominator #=> 1
Rational(9, -4).denominator #=> 4
Rational(-2, -10).denominator #=> 5
rat.numerator.gcd(rat.denominator) #=> 1
@overload denominator
@return [Integer];T;%0;"@&;'F;)o;*;+T;,ix;-i;.@; I"static VALUE;T;/I"\static VALUE
nurat_denominator(VALUE self)
{
get_dat1(self);
return dat->den;
};T;0To;
;F;;
;;;I"Rational#+;F;[[I"
other;T0;[[@i;T;:+;0;[ ;{ ;IC;"Performs addition.
Rational(2, 3) + Rational(2, 3) #=> (4/3)
Rational(900) + Rational(1) #=> (900/1)
Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
Rational(9, 8) + 4 #=> (41/8)
Rational(20, 9) + 9.8 #=> 12.022222222222222
;T;[o;
;I"
overload;F;0;;2;0; I"+(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@A;#[ ;$I"@return [Numeric];T;%0;"@A;&0;'F;(i ;[[I"numeric;T0;"@A;#[ ;$I"APerforms addition.
Rational(2, 3) + Rational(2, 3) #=> (4/3)
Rational(900) + Rational(1) #=> (900/1)
Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
Rational(9, 8) + 4 #=> (41/8)
Rational(20, 9) + 9.8 #=> 12.022222222222222
@overload +(numeric)
@return [Numeric];T;%0;"@A;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"+static VALUE
nurat_add(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
{
get_dat1(self);
return f_addsub(self,
dat->num, dat->den,
other, ONE, '+');
}
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return f_add(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
{
get_dat2(self, other);
return f_addsub(self,
adat->num, adat->den,
bdat->num, bdat->den, '+');
}
}
else {
return rb_num_coerce_bin(self, other, '+');
}
};T;0To;
;F;;
;;;I"Rational#-;F;[[I"
other;T0;[[@i;T;:-;0;[ ;{ ;IC;"Performs subtraction.
Rational(2, 3) - Rational(2, 3) #=> (0/1)
Rational(900) - Rational(1) #=> (899/1)
Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
Rational(9, 8) - 4 #=> (23/8)
Rational(20, 9) - 9.8 #=> -7.577777777777778
;T;[o;
;I"
overload;F;0;;3;0; I"-(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@`;#[ ;$I"@return [Numeric];T;%0;"@`;&0;'F;(i ;[[I"numeric;T0;"@`;#[ ;$I"CPerforms subtraction.
Rational(2, 3) - Rational(2, 3) #=> (0/1)
Rational(900) - Rational(1) #=> (899/1)
Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
Rational(9, 8) - 4 #=> (23/8)
Rational(20, 9) - 9.8 #=> -7.577777777777778
@overload -(numeric)
@return [Numeric];T;%0;"@`;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"+static VALUE
nurat_sub(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
{
get_dat1(self);
return f_addsub(self,
dat->num, dat->den,
other, ONE, '-');
}
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return f_sub(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
{
get_dat2(self, other);
return f_addsub(self,
adat->num, adat->den,
bdat->num, bdat->den, '-');
}
}
else {
return rb_num_coerce_bin(self, other, '-');
}
};T;0To;
;F;;
;;;I"Rational#*;F;[[I"
other;T0;[[@id;T;:*;0;[ ;{ ;IC;"Performs multiplication.
Rational(2, 3) * Rational(2, 3) #=> (4/9)
Rational(900) * Rational(1) #=> (900/1)
Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
Rational(9, 8) * 4 #=> (9/2)
Rational(20, 9) * 9.8 #=> 21.77777777777778
;T;[o;
;I"
overload;F;0;;4;0; I"*(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@;#[ ;$I"@return [Numeric];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@;#[ ;$I"BPerforms multiplication.
Rational(2, 3) * Rational(2, 3) #=> (4/9)
Rational(900) * Rational(1) #=> (900/1)
Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
Rational(9, 8) * 4 #=> (9/2)
Rational(20, 9) * 9.8 #=> 21.77777777777778
@overload *(numeric)
@return [Numeric];T;%0;"@;'F;)o;*;+T;,iX;-ib;.@; I"static VALUE;T;/I"+static VALUE
nurat_mul(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
{
get_dat1(self);
return f_muldiv(self,
dat->num, dat->den,
other, ONE, '*');
}
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return f_mul(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
{
get_dat2(self, other);
return f_muldiv(self,
adat->num, adat->den,
bdat->num, bdat->den, '*');
}
}
else {
return rb_num_coerce_bin(self, other, '*');
}
};T;0To;
;F;;
;;;I"Rational#/;F;[[I"
other;T0;[[@i;T;:/;0;[ ;{ ;IC;"Performs division.
Rational(2, 3) / Rational(2, 3) #=> (1/1)
Rational(900) / Rational(1) #=> (900/1)
Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
Rational(9, 8) / 4 #=> (9/32)
Rational(20, 9) / 9.8 #=> 0.22675736961451246
;T;[o;
;I"
overload;F;0;;5;0; I"/(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@;#[ ;$I"@return [Numeric];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@o;
;I"
overload;F;0;:quo;0; I"quo(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@;#[ ;$I"@return [Numeric];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@;#[ ;$I"kPerforms division.
Rational(2, 3) / Rational(2, 3) #=> (1/1)
Rational(900) / Rational(1) #=> (900/1)
Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
Rational(9, 8) / 4 #=> (9/32)
Rational(20, 9) / 9.8 #=> 0.22675736961451246
@overload /(numeric)
@return [Numeric]
@overload quo(numeric)
@return [Numeric];T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_div(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
if (f_zero_p(other))
rb_raise_zerodiv();
{
get_dat1(self);
return f_muldiv(self,
dat->num, dat->den,
other, ONE, '/');
}
}
else if (RB_TYPE_P(other, T_FLOAT))
return rb_funcall(f_to_f(self), '/', 1, other);
else if (RB_TYPE_P(other, T_RATIONAL)) {
if (f_zero_p(other))
rb_raise_zerodiv();
{
get_dat2(self, other);
if (f_one_p(self))
return f_rational_new_no_reduce2(CLASS_OF(self),
bdat->den, bdat->num);
return f_muldiv(self,
adat->num, adat->den,
bdat->num, bdat->den, '/');
}
}
else {
return rb_num_coerce_bin(self, other, '/');
}
};T;0To;
;F;;
;;;I"Rational#quo;F;[[I"
other;T0;[[@i;T;;6;0;[ ;{ ;IC;"Performs division.
Rational(2, 3) / Rational(2, 3) #=> (1/1)
Rational(900) / Rational(1) #=> (900/1)
Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
Rational(9, 8) / 4 #=> (9/32)
Rational(20, 9) / 9.8 #=> 0.22675736961451246
;T;[o;
;I"
overload;F;0;;5;0; I"/(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@;#[ ;$I"@return [Numeric];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@o;
;I"
overload;F;0;;6;0; I"quo(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@;#[ ;$I"@return [Numeric];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@;#[ ;$@;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_div(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
if (f_zero_p(other))
rb_raise_zerodiv();
{
get_dat1(self);
return f_muldiv(self,
dat->num, dat->den,
other, ONE, '/');
}
}
else if (RB_TYPE_P(other, T_FLOAT))
return rb_funcall(f_to_f(self), '/', 1, other);
else if (RB_TYPE_P(other, T_RATIONAL)) {
if (f_zero_p(other))
rb_raise_zerodiv();
{
get_dat2(self, other);
if (f_one_p(self))
return f_rational_new_no_reduce2(CLASS_OF(self),
bdat->den, bdat->num);
return f_muldiv(self,
adat->num, adat->den,
bdat->num, bdat->den, '/');
}
}
else {
return rb_num_coerce_bin(self, other, '/');
}
};T;0To;
;F;;
;;;I"Rational#fdiv;F;[[I"
other;T0;[[@i;T;: fdiv;0;[ ;{ ;IC;"Performs division and returns the value as a float.
Rational(2, 3).fdiv(1) #=> 0.6666666666666666
Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333
Rational(2).fdiv(3) #=> 0.6666666666666666
;T;[o;
;I"
overload;F;0;;7;0; I"fdiv(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"
Float;T;"@;#[ ;$I"@return [Float];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@;#[ ;$I"Performs division and returns the value as a float.
Rational(2, 3).fdiv(1) #=> 0.6666666666666666
Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333
Rational(2).fdiv(3) #=> 0.6666666666666666
@overload fdiv(numeric)
@return [Float];T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_fdiv(VALUE self, VALUE other)
{
if (f_zero_p(other))
return f_div(self, f_to_f(other));
return f_to_f(f_div(self, other));
};T;0To;
;F;;
;;;I"Rational#**;F;[[I"
other;T0;[[@i;T;:**;0;[ ;{ ;IC;"DPerforms exponentiation.
Rational(2) ** Rational(3) #=> (8/1)
Rational(10) ** -2 #=> (1/100)
Rational(10) ** -2.0 #=> 0.01
Rational(-4) ** Rational(1,2) #=> (1.2246063538223773e-16+2.0i)
Rational(1, 2) ** 0 #=> (1/1)
Rational(1, 2) ** 0.0 #=> 1.0
;T;[o;
;I"
overload;F;0;;8;0; I"**(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Numeric;T;"@;#[ ;$I"@return [Numeric];T;%0;"@;&0;'F;(i ;[[I"numeric;T0;"@;#[ ;$I"pPerforms exponentiation.
Rational(2) ** Rational(3) #=> (8/1)
Rational(10) ** -2 #=> (1/100)
Rational(10) ** -2.0 #=> 0.01
Rational(-4) ** Rational(1,2) #=> (1.2246063538223773e-16+2.0i)
Rational(1, 2) ** 0 #=> (1/1)
Rational(1, 2) ** 0.0 #=> 1.0
@overload **(numeric)
@return [Numeric];T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"cstatic VALUE
nurat_expt(VALUE self, VALUE other)
{
if (k_numeric_p(other) && k_exact_zero_p(other))
return f_rational_new_bang1(CLASS_OF(self), ONE);
if (k_rational_p(other)) {
get_dat1(other);
if (f_one_p(dat->den))
other = dat->num; /* c14n */
}
/* Deal with special cases of 0**n and 1**n */
if (k_numeric_p(other) && k_exact_p(other)) {
get_dat1(self);
if (f_one_p(dat->den)) {
if (f_one_p(dat->num)) {
return f_rational_new_bang1(CLASS_OF(self), ONE);
}
else if (f_minus_one_p(dat->num) && k_integer_p(other)) {
return f_rational_new_bang1(CLASS_OF(self), INT2FIX(f_odd_p(other) ? -1 : 1));
}
else if (f_zero_p(dat->num)) {
if (FIX2INT(f_cmp(other, ZERO)) == -1) {
rb_raise_zerodiv();
}
else {
return f_rational_new_bang1(CLASS_OF(self), ZERO);
}
}
}
}
/* General case */
if (RB_TYPE_P(other, T_FIXNUM)) {
{
VALUE num, den;
get_dat1(self);
switch (FIX2INT(f_cmp(other, ZERO))) {
case 1:
num = f_expt(dat->num, other);
den = f_expt(dat->den, other);
break;
case -1:
num = f_expt(dat->den, f_negate(other));
den = f_expt(dat->num, f_negate(other));
break;
default:
num = ONE;
den = ONE;
break;
}
return f_rational_new2(CLASS_OF(self), num, den);
}
}
else if (RB_TYPE_P(other, T_BIGNUM)) {
rb_warn("in a**b, b may be too big");
return f_expt(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_FLOAT) || RB_TYPE_P(other, T_RATIONAL)) {
return f_expt(f_to_f(self), other);
}
else {
return rb_num_coerce_bin(self, other, id_expt);
}
};T;0To;
;F;;
;;;I"Rational#<=>;F;[[I"
other;T0;[[@i.;T;:<=>;0;[ ;{ ;IC;"GPerforms comparison and returns -1, 0, or +1.
+nil+ is returned if the two values are incomparable.
Rational(2, 3) <=> Rational(2, 3) #=> 0
Rational(5) <=> 5 #=> 0
Rational(2,3) <=> Rational(1,3) #=> 1
Rational(1,3) <=> 1 #=> -1
Rational(1,3) <=> 0.3 #=> 1
;T;[o;
;I"
overload;F;0;;9;0; I"<=>(numeric);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[ I"-1;TI"0;TI"+1;TI"nil;T;"@2;#[ ;$I" @return [ -1, 0, +1, nil];T;%0;"@2;&0;'F;(i ;[[I"numeric;T0;"@2;#[ ;$I"~Performs comparison and returns -1, 0, or +1.
+nil+ is returned if the two values are incomparable.
Rational(2, 3) <=> Rational(2, 3) #=> 0
Rational(5) <=> 5 #=> 0
Rational(2,3) <=> Rational(1,3) #=> 1
Rational(1,3) <=> 1 #=> -1
Rational(1,3) <=> 0.3 #=> 1
@overload <=>(numeric)
@return [ -1, 0, +1, nil];T;%0;"@2;'F;)o;*;+T;,i ;-i,;.@; I"static VALUE;T;/I"static VALUE
nurat_cmp(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
{
get_dat1(self);
if (FIXNUM_P(dat->den) && FIX2LONG(dat->den) == 1)
return f_cmp(dat->num, other); /* c14n */
return f_cmp(self, f_rational_new_bang1(CLASS_OF(self), other));
}
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return f_cmp(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
{
VALUE num1, num2;
get_dat2(self, other);
if (FIXNUM_P(adat->num) && FIXNUM_P(adat->den) &&
FIXNUM_P(bdat->num) && FIXNUM_P(bdat->den)) {
num1 = f_imul(FIX2LONG(adat->num), FIX2LONG(bdat->den));
num2 = f_imul(FIX2LONG(bdat->num), FIX2LONG(adat->den));
}
else {
num1 = f_mul(adat->num, bdat->den);
num2 = f_mul(bdat->num, adat->den);
}
return f_cmp(f_sub(num1, num2), ZERO);
}
}
else {
return rb_num_coerce_cmp(self, other, id_cmp);
}
};T;0To;
;F;;
;;;I"Rational#==;F;[[I"
other;T0;[[@i`;T;:==;0;[ ;{ ;IC;"!Returns true if rat equals object numerically.
Rational(2, 3) == Rational(2, 3) #=> true
Rational(5) == 5 #=> true
Rational(0) == 0.0 #=> true
Rational('1/3') == 0.33 #=> false
Rational('1/2') == '1/2' #=> false
;T;[o;
;I"
overload;F;0;;:;0; I"==(object);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@T;#[ ;$I"@return [Boolean];T;%0;"@T;&0;'F;(i ;[[I"object;T0;"@T;#[ ;$I"LReturns true if rat equals object numerically.
Rational(2, 3) == Rational(2, 3) #=> true
Rational(5) == 5 #=> true
Rational(0) == 0.0 #=> true
Rational('1/3') == 0.33 #=> false
Rational('1/2') == '1/2' #=> false
@overload ==(object)
@return [Boolean];T;%0;"@T;'F;)o;*;+T;,iT;-i^;.@; I"static VALUE;T;/I"
static VALUE
nurat_eqeq_p(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
{
get_dat1(self);
if (f_zero_p(dat->num) && f_zero_p(other))
return Qtrue;
if (!FIXNUM_P(dat->den))
return Qfalse;
if (FIX2LONG(dat->den) != 1)
return Qfalse;
if (f_eqeq_p(dat->num, other))
return Qtrue;
return Qfalse;
}
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return f_eqeq_p(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
{
get_dat2(self, other);
if (f_zero_p(adat->num) && f_zero_p(bdat->num))
return Qtrue;
return f_boolcast(f_eqeq_p(adat->num, bdat->num) &&
f_eqeq_p(adat->den, bdat->den));
}
}
else {
return f_eqeq_p(other, self);
}
};T;0To;
;F;;
;;;I"Rational#coerce;F;[[I"
other;T0;[[@i;T;:coerce;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@s;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_coerce(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
return rb_assoc_new(f_rational_new_bang1(CLASS_OF(self), other), self);
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return rb_assoc_new(other, f_to_f(self));
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
return rb_assoc_new(other, self);
}
else if (RB_TYPE_P(other, T_COMPLEX)) {
if (k_exact_zero_p(RCOMPLEX(other)->imag))
return rb_assoc_new(f_rational_new_bang1
(CLASS_OF(self), RCOMPLEX(other)->real), self);
else
return rb_assoc_new(other, rb_Complex(self, INT2FIX(0)));
}
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
rb_obj_classname(other), rb_obj_classname(self));
return Qnil;
};T;0To;
;F;;
;;;I"Rational#quot;F;[[I"
other;T0;[[@i;T;: quot;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"dstatic VALUE
nurat_quot(VALUE self, VALUE other)
{
return f_truncate(f_div(self, other));
};T;0To;
;F;;
;;;I"Rational#quotrem;F;[[I"
other;T0;[[@i;T;:quotrem;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_quotrem(VALUE self, VALUE other)
{
VALUE val = f_truncate(f_div(self, other));
return rb_assoc_new(val, f_sub(self, f_mul(other, val)));
};T;0To;
;F;;
;;;I"Rational#rational?;F;[ ;[[@i;T;:rational?;0;[ ;{ ;IC;":nodoc:
;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@;#[ ;$I":nodoc:;T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I">static VALUE
nurat_true(VALUE self)
{
return Qtrue;
};T;0To;
;F;;
;;;I"Rational#exact?;F;[ ;[[@i;T;:exact?;0;[ ;{ ;IC;":nodoc:
;T;[o;!
;I"return;F;@;0;[@;"@;#[ ;$@;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I">static VALUE
nurat_true(VALUE self)
{
return Qtrue;
};T;0To;
;F;;
;;;I"Rational#floor;F;[[I"
*args;T0;[[@i5;T;:
floor;0;[ ;{ ;IC;"Returns the truncated value (toward negative infinity).
Rational(3).floor #=> 3
Rational(2, 3).floor #=> 0
Rational(-3, 2).floor #=> -1
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').floor(+1) #=> "-123.500000"
'%f' % Rational('-123.456').floor(-1) #=> "-130.000000"
;T;[o;
;I"
overload;F;0;;@;0; I"
floor;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Integer;T;"@;#[ ;$I"@return [Integer];T;%0;"@;&0;'F;(i ;[ ;"@o;
;I"
overload;F;0;;@;0; I"floor(precision=0);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"precision;TI"0;T;"@;#[ ;$I"Returns the truncated value (toward negative infinity).
Rational(3).floor #=> 3
Rational(2, 3).floor #=> 0
Rational(-3, 2).floor #=> -1
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').floor(+1) #=> "-123.500000"
'%f' % Rational('-123.456').floor(-1) #=> "-130.000000"
@overload floor
@return [Integer]
@overload floor(precision=0);T;%0;"@;'F;)o;*;+T;,i#;-i3;.@; I"static VALUE;T;/I"{static VALUE
nurat_floor_n(int argc, VALUE *argv, VALUE self)
{
return f_round_common(argc, argv, self, nurat_floor);
};T;0To;
;F;;
;;;I"Rational#ceil;F;[[@0;[[@iM;T;: ceil;0;[ ;{ ;IC;"Returns the truncated value (toward positive infinity).
Rational(3).ceil #=> 3
Rational(2, 3).ceil #=> 1
Rational(-3, 2).ceil #=> -1
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').ceil(+1) #=> "-123.400000"
'%f' % Rational('-123.456').ceil(-1) #=> "-120.000000"
;T;[o;
;I"
overload;F;0;;A;0; I" ceil;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Integer;T;"@;#[ ;$I"@return [Integer];T;%0;"@;&0;'F;(i ;[ ;"@o;
;I"
overload;F;0;;A;0; I"ceil(precision=0);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"precision;TI"0;T;"@;#[ ;$I"Returns the truncated value (toward positive infinity).
Rational(3).ceil #=> 3
Rational(2, 3).ceil #=> 1
Rational(-3, 2).ceil #=> -1
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').ceil(+1) #=> "-123.400000"
'%f' % Rational('-123.456').ceil(-1) #=> "-120.000000"
@overload ceil
@return [Integer]
@overload ceil(precision=0);T;%0;"@;'F;)o;*;+T;,i;;-iK;.@; I"static VALUE;T;/I"~static VALUE
nurat_ceil_n(int argc, VALUE *argv, VALUE self)
{
return f_round_common(argc, argv, self, nurat_ceil);
};T;0To;
;F;;
;;;I"Rational#truncate;F;[[@0;[[@ie;T;:
truncate;0;[ ;{ ;IC;"Returns the truncated value (toward zero).
Rational(3).truncate #=> 3
Rational(2, 3).truncate #=> 0
Rational(-3, 2).truncate #=> -1
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').truncate(+1) #=> "-123.400000"
'%f' % Rational('-123.456').truncate(-1) #=> "-120.000000"
;T;[o;
;I"
overload;F;0;;B;0; I"
truncate;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Integer;T;"@;#[ ;$I"@return [Integer];T;%0;"@;&0;'F;(i ;[ ;"@o;
;I"
overload;F;0;;B;0; I"truncate(precision=0);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"precision;TI"0;T;"@;#[ ;$I"Returns the truncated value (toward zero).
Rational(3).truncate #=> 3
Rational(2, 3).truncate #=> 0
Rational(-3, 2).truncate #=> -1
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').truncate(+1) #=> "-123.400000"
'%f' % Rational('-123.456').truncate(-1) #=> "-120.000000"
@overload truncate
@return [Integer]
@overload truncate(precision=0);T;%0;"@;'F;)o;*;+T;,iS;-ic;.@; I"static VALUE;T;/I"static VALUE
nurat_truncate_n(int argc, VALUE *argv, VALUE self)
{
return f_round_common(argc, argv, self, nurat_truncate);
};T;0To;
;F;;
;;;I"Rational#round;F;[[@0;[[@i~;T;:
round;0;[ ;{ ;IC;"Returns the truncated value (toward the nearest integer;
0.5 => 1; -0.5 => -1).
Rational(3).round #=> 3
Rational(2, 3).round #=> 1
Rational(-3, 2).round #=> -2
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').round(+1) #=> "-123.500000"
'%f' % Rational('-123.456').round(-1) #=> "-120.000000"
;T;[o;
;I"
overload;F;0;;C;0; I"
round;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Integer;T;"@<;#[ ;$I"@return [Integer];T;%0;"@<;&0;'F;(i ;[ ;"@<o;
;I"
overload;F;0;;C;0; I"round(precision=0);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@<;&0;'F;(i ;[[I"precision;TI"0;T;"@<;#[ ;$I"Returns the truncated value (toward the nearest integer;
0.5 => 1; -0.5 => -1).
Rational(3).round #=> 3
Rational(2, 3).round #=> 1
Rational(-3, 2).round #=> -2
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').round(+1) #=> "-123.500000"
'%f' % Rational('-123.456').round(-1) #=> "-120.000000"
@overload round
@return [Integer]
@overload round(precision=0);T;%0;"@<;'F;)o;*;+T;,ik;-i|;.@; I"static VALUE;T;/I"{static VALUE
nurat_round_n(int argc, VALUE *argv, VALUE self)
{
return f_round_common(argc, argv, self, nurat_round);
};T;0To;
;F;;
;;;I"Rational#to_i;F;[ ;[[@i;T;: to_i;0;[ ;{ ;IC;"Returns the truncated value as an integer.
Equivalent to
rat.truncate.
Rational(2, 3).to_i #=> 0
Rational(3).to_i #=> 3
Rational(300.6).to_i #=> 300
Rational(98,71).to_i #=> 1
Rational(-30,2).to_i #=> -15
;T;[o;
;I"
overload;F;0;;D;0; I" to_i;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Integer;T;"@c;#[ ;$I"@return [Integer];T;%0;"@c;&0;'F;(i ;[ ;"@c;#[ ;$I"Returns the truncated value as an integer.
Equivalent to
rat.truncate.
Rational(2, 3).to_i #=> 0
Rational(3).to_i #=> 3
Rational(300.6).to_i #=> 300
Rational(98,71).to_i #=> 1
Rational(-30,2).to_i #=> -15
@overload to_i
@return [Integer];T;%0;"@c;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_truncate(VALUE self)
{
get_dat1(self);
if (f_negative_p(dat->num))
return f_negate(f_idiv(f_negate(dat->num), dat->den));
return f_idiv(dat->num, dat->den);
};T;0To;
;F;;
;;;I"Rational#to_f;F;[ ;[[@i;T;: to_f;0;[ ;{ ;IC;"Return the value as a float.
Rational(2).to_f #=> 2.0
Rational(9, 4).to_f #=> 2.25
Rational(-3, 4).to_f #=> -0.75
Rational(20, 3).to_f #=> 6.666666666666667
;T;[o;
;I"
overload;F;0;;E;0; I" to_f;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"
Float;T;"@~;#[ ;$I"@return [Float];T;%0;"@~;&0;'F;(i ;[ ;"@~;#[ ;$I"Return the value as a float.
Rational(2).to_f #=> 2.0
Rational(9, 4).to_f #=> 2.25
Rational(-3, 4).to_f #=> -0.75
Rational(20, 3).to_f #=> 6.666666666666667
@overload to_f
@return [Float];T;%0;"@~;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"gstatic VALUE
nurat_to_f(VALUE self)
{
get_dat1(self);
return f_fdiv(dat->num, dat->den);
};T;0To;
;F;;
;;;I"Rational#to_r;F;[ ;[[@i;T;: to_r;0;[ ;{ ;IC;"ZReturns self.
Rational(2).to_r #=> (2/1)
Rational(-8, 6).to_r #=> (-4/3)
;T;[o;
;I"
overload;F;0;;F;0; I" to_r;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I" self;T;"@;#[ ;$I"@return [self];T;%0;"@;&0;'F;(i ;[ ;"@;#[ ;$I"|Returns self.
Rational(2).to_r #=> (2/1)
Rational(-8, 6).to_r #=> (-4/3)
@overload to_r
@return [self];T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"=static VALUE
nurat_to_r(VALUE self)
{
return self;
};T;0To;
;F;;
;;;I"Rational#rationalize;F;[[@0;[[@i;T;:rationalize;0;[ ;{ ;IC;"BReturns a simpler approximation of the value if the optional
argument eps is given (rat-|eps| <= result <= rat+|eps|), self
otherwise.
r = Rational(5033165, 16777216)
r.rationalize #=> (5033165/16777216)
r.rationalize(Rational('0.01')) #=> (3/10)
r.rationalize(Rational('0.1')) #=> (1/3)
;T;[o;
;I"
overload;F;0;;G;0; I"rationalize;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I" self;T;"@;#[ ;$I"@return [self];T;%0;"@;&0;'F;(i ;[ ;"@o;
;I"
overload;F;0;;G;0; I"rationalize(eps);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"eps;T0;"@;#[ ;$I"Returns a simpler approximation of the value if the optional
argument eps is given (rat-|eps| <= result <= rat+|eps|), self
otherwise.
r = Rational(5033165, 16777216)
r.rationalize #=> (5033165/16777216)
r.rationalize(Rational('0.01')) #=> (3/10)
r.rationalize(Rational('0.1')) #=> (1/3)
@overload rationalize
@return [self]
@overload rationalize(eps);T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_rationalize(int argc, VALUE *argv, VALUE self)
{
VALUE e, a, b, p, q;
if (argc == 0)
return self;
if (f_negative_p(self))
return f_negate(nurat_rationalize(argc, argv, f_abs(self)));
rb_scan_args(argc, argv, "01", &e);
e = f_abs(e);
a = f_sub(self, e);
b = f_add(self, e);
if (f_eqeq_p(a, b))
return self;
nurat_rationalize_internal(a, b, &p, &q);
return f_rational_new2(CLASS_OF(self), p, q);
};T;0To;
;F;;
;;;I"Rational#hash;F;[ ;[[@i+;T;: hash;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@;'F;)o;*;+T;,i*;-i*;.@; I"static VALUE;T;/I"static VALUE
nurat_hash(VALUE self)
{
st_index_t v, h[2];
VALUE n;
get_dat1(self);
n = rb_hash(dat->num);
h[0] = NUM2LONG(n);
n = rb_hash(dat->den);
h[1] = NUM2LONG(n);
v = rb_memhash(h, sizeof(h));
return LONG2FIX(v);
};T;0To;
;F;;
;;;I"Rational#to_s;F;[ ;[[@iQ;T;: to_s;0;[ ;{ ;IC;"Returns the value as a string.
Rational(2).to_s #=> "2/1"
Rational(-8, 6).to_s #=> "-4/3"
Rational('1/2').to_s #=> "1/2"
;T;[o;
;I"
overload;F;0;;I;0; I" to_s;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"String;T;"@;#[ ;$I"@return [String];T;%0;"@;&0;'F;(i ;[ ;"@;#[ ;$I"Returns the value as a string.
Rational(2).to_s #=> "2/1"
Rational(-8, 6).to_s #=> "-4/3"
Rational('1/2').to_s #=> "1/2"
@overload to_s
@return [String];T;%0;"@;'F;)o;*;+T;,iG;-iO;.@; I"static VALUE;T;/I"Ostatic VALUE
nurat_to_s(VALUE self)
{
return f_format(self, f_to_s);
};T;0To;
;F;;
;;;I"Rational#inspect;F;[ ;[[@ia;T;:inspect;0;[ ;{ ;IC;"Returns the value as a string for inspection.
Rational(2).inspect #=> "(2/1)"
Rational(-8, 6).inspect #=> "(-4/3)"
Rational('1/2').inspect #=> "(1/2)"
;T;[o;
;I"
overload;F;0;;J;0; I"inspect;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"String;T;"@;#[ ;$I"@return [String];T;%0;"@;&0;'F;(i ;[ ;"@;#[ ;$I"Returns the value as a string for inspection.
Rational(2).inspect #=> "(2/1)"
Rational(-8, 6).inspect #=> "(-4/3)"
Rational('1/2').inspect #=> "(1/2)"
@overload inspect
@return [String];T;%0;"@;'F;)o;*;+T;,iW;-i_;.@; I"static VALUE;T;/I"static VALUE
nurat_inspect(VALUE self)
{
VALUE s;
s = rb_usascii_str_new2("(");
rb_str_concat(s, f_format(self, f_inspect));
rb_str_cat2(s, ")");
return s;
};T;0To;
;F;;
;:private;I"Rational#marshal_dump;F;[ ;[[@i;T;:marshal_dump;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@;'F;)o;*;+T;,i;-i;.@; I"static VALUE;T;/I"static VALUE
nurat_marshal_dump(VALUE self)
{
VALUE a;
get_dat1(self);
a = rb_assoc_new(dat->num, dat->den);
rb_copy_generic_ivar(a, self);
return a;
};T;0To; ;IC;[o;
;F;;
;;K;I"&Rational::compatible#marshal_load;F;[[I"a;T0;[[@i;T;:marshal_load;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@.;'F;)o;*;+T;,i;-i;.@,; I"static VALUE;T;/I"static VALUE
nurat_marshal_load(VALUE self, VALUE a)
{
rb_check_frozen(self);
rb_check_trusted(self);
Check_Type(a, T_ARRAY);
if (RARRAY_LEN(a) != 2)
rb_raise(rb_eArgError, "marshaled rational must have an array whose length is 2 but %ld", RARRAY_LEN(a));
if (f_zero_p(RARRAY_AREF(a, 1)))
rb_raise_zerodiv();
rb_ivar_set(self, id_i_num, RARRAY_AREF(a, 0));
rb_ivar_set(self, id_i_den, RARRAY_AREF(a, 1));
return self;
};T;0T:@owner@,:@class_mixinsIC;[ ;N@,:@instance_mixinsIC;[ ;N@,:@attributesIC:SymbolHash{:
classIC;R{ :@symbolize_valueT;
IC;R{ ;TT;TT:
@aliases{ :@groups[ ;[[@i
;F;:compatible;: ruby;;;[ ;{ ;IC;" ;T;[ ;#[ ;$@;%0;"@,;(i ;.@;I"Rational::compatible;F:@superclasso:YARD::CodeObjects::Proxy:@orignamespace0:@origname0:
@imethod0;:Object;.@: @objo; ;IC;[@o;
;F;;
;;;I"Object#assert_Qundef;F;[[I"obj;T0[I"msg;T0;[[I"ext/ripper/ripper.c;TiF[I"parse.c;TiF;T;:assert_Qundef;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@P;'F;)o;*;+T;,i~F;-i~F;.@N; I"static VALUE;T;/I"static VALUE
ripper_assert_Qundef(VALUE self, VALUE obj, VALUE msg)
{
StringValue(msg);
if (obj == Qundef) {
rb_raise(rb_eArgError, "%"PRIsVALUE, msg);
}
return Qnil;
};T;0To;
;F;;
;;;I"Object#rawVALUE;F;[[I"obj;T0;[[@YiF[@[iF;T;:
rawVALUE;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@e;'F;)o;*;+T;,iF;-iF;.@N; I"static VALUE;T;/I"Tstatic VALUE
ripper_value(VALUE self, VALUE obj)
{
return ULONG2NUM(obj);
};T;0To;
;F;;
;;;I"Object#validate_object;F;[[I"x;T0;[[@YiCE[@[iD;T;:validate_object;0;[ ;{ ;IC;":nodoc:
;T;[ ;#[ ;$I":nodoc:;T;%0;"@v;'F;)o;*;+T;,iD;-iD;.@N; I"static VALUE;T;/I"Ustatic VALUE
ripper_validate_object(VALUE self, VALUE x)
{
if (x == Qfalse) return x;
if (x == Qtrue) return x;
if (x == Qnil) return x;
if (x == Qundef)
rb_raise(rb_eArgError, "Qundef given");
if (FIXNUM_P(x)) return x;
if (SYMBOL_P(x)) return x;
if (!rb_is_pointer_to_heap(x))
rb_raise(rb_eArgError, "invalid pointer: %p", x);
switch (BUILTIN_TYPE(x)) {
case T_STRING:
case T_OBJECT:
case T_ARRAY:
case T_BIGNUM:
case T_FLOAT:
case T_COMPLEX:
case T_RATIONAL:
return x;
case T_NODE:
if (nd_type(x) != NODE_RIPPER) {
rb_raise(rb_eArgError, "NODE given: %p", x);
}
return ((NODE *)x)->nd_rval;
default:
rb_raise(rb_eArgError, "wrong type of ruby object: %p (%s)",
x, rb_obj_classname(x));
}
return x;
};T;0To;
;F;;
;;;I"Object#method;F;[[I"vid;T0;[[I"proc.c;TiE;T;:method;0;[ ;{ ;IC;"@Looks up the named method as a receiver in obj, returning a
Method
object (or raising NameError
). The
Method
object acts as a closure in obj's object
instance, so instance variables and the value of self
remain available.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
m = k.method(:hello)
m.call #=> "Hello, @iv = 99"
l = Demo.new('Fred')
m = l.method("hello")
m.call #=> "Hello, @iv = Fred"
;T;[o;
;I"
overload;F;0;;c;0; I"method(sym);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"sym;T0;"@;#[ ;$I"XLooks up the named method as a receiver in obj, returning a
Method
object (or raising NameError
). The
Method
object acts as a closure in obj's object
instance, so instance variables and the value of self
remain available.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
m = k.method(:hello)
m.call #=> "Hello, @iv = 99"
l = Demo.new('Fred')
m = l.method("hello")
m.call #=> "Hello, @iv = Fred"
@overload method(sym);T;%0;"@;'F;)o;*;+T;,i);-iA;.@N; I"
VALUE;T;/I"ZVALUE
rb_obj_method(VALUE obj, VALUE vid)
{
return obj_method(obj, vid, FALSE);
};T;0To;
;F;;
;;;I"Object#public_method;F;[[I"vid;T0;[[@iR;T;:public_method;0;[ ;{ ;IC;"6Similar to _method_, searches public method only.
;T;[o;
;I"
overload;F;0;;d;0; I"public_method(sym);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"sym;T0;"@;#[ ;$I"USimilar to _method_, searches public method only.
@overload public_method(sym);T;%0;"@;'F;)o;*;+T;,iK;-iN;.@N; I"
VALUE;T;/I"`VALUE
rb_obj_public_method(VALUE obj, VALUE vid)
{
return obj_method(obj, vid, TRUE);
};T;0To;
;F;;
;;;I"Object#singleton_method;F;[[I"vid;T0;[[@ip;T;:singleton_method;0;[ ;{ ;IC;"^Similar to _method_, searches singleton method only.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi)
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) #=> NameError
;T;[o;
;I"
overload;F;0;;e;0; I"singleton_method(sym);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"sym;T0;"@;#[ ;$I"Similar to _method_, searches singleton method only.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi)
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) #=> NameError
@overload singleton_method(sym);T;%0;"@;'F;)o;*;+T;,iX;-il;.@N; I"
VALUE;T;/I"VALUE
rb_obj_singleton_method(VALUE obj, VALUE vid)
{
const rb_method_entry_t *me;
VALUE klass;
ID id = rb_check_id(&vid);
if (!id) {
if (!NIL_P(klass = rb_singleton_class_get(obj)) &&
respond_to_missing_p(klass, obj, vid, FALSE)) {
id = rb_intern_str(vid);
return mnew_missing(klass, obj, id, id, rb_cMethod);
}
undef:
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
obj, vid);
}
if (NIL_P(klass = rb_singleton_class_get(obj)) ||
UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) ||
UNDEFINED_REFINED_METHOD_P(me->def)) {
vid = ID2SYM(id);
goto undef;
}
return mnew_from_me(me, klass, obj, id, rb_cMethod, FALSE);
};T;0To;
;F;;
;;;I"#Object#define_singleton_method;F;[[@0;[[@i];T;:define_singleton_method;0;[ ;{ ;IC;"Defines a singleton method in the receiver. The _method_
parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object.
If a block is specified, it is used as the method body.
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
;T;[o;
;I"
overload;F;0;;f;0; I",define_singleton_method(symbol, method);T;IC;" ;T;[ ;#[ ;$I" ;T;%0;"@;&0;'F;(i ;[[I"symbol;T0[I"method;T0;"@o;
;I"
overload;F;0;;f;0; I"$define_singleton_method(symbol);T;IC;" ;T;[o;!
;I"
yield;F;I"[];T;0;0;"@o;!
;I"return;F;I" ;T;0;[I" Proc;T;"@;#[ ;$I"@yield []
@return [Proc];T;%0;"@;&0;'F;(i ;[[I"symbol;T0;"@;#[ ;$I"vDefines a singleton method in the receiver. The _method_
parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object.
If a block is specified, it is used as the method body.
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
@overload define_singleton_method(symbol, method)
@overload define_singleton_method(symbol)
@yield []
@return [Proc];T;%0;"@;'F;)o;*;+T;,iC;-i[;.@N; I"static VALUE;T;/I"static VALUE
rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
{
VALUE klass = rb_singleton_class(obj);
return rb_mod_define_method(argc, argv, klass);
};T;0To;
;F;;
;;;I"Object#to_enum;F;[[@0;[[I"enumerator.c;Ti;T;:to_enum;0;[ ;{ ;IC;"6Creates a new Enumerator which will enumerate by calling +method+ on
+obj+, passing +args+ if any.
If a block is given, it will be used to calculate the size of
the enumerator without the need to iterate it (see Enumerator#size).
=== Examples
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122
# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)
It is typical to call to_enum when defining methods for
a generic Enumerable, in case no block is passed.
Here is such an example, with parameter passing and a sizing block:
module Enumerable
# a generic method to repeat the values of any enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
return to_enum(__method__, n) do # __method__ is :repeat here
sz = size # Call size and multiply by n...
sz * n if sz # but return nil if size itself is nil
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
;T;[ o;
;I"
overload;F;0;;g;0; I"#to_enum(method = :each, *args);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@;#[ ;$I"@return [Enumerator];T;%0;"@;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@o;
;I"
overload;F;0;:
enum_for;0; I"$enum_for(method = :each, *args);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@;#[ ;$I"@return [Enumerator];T;%0;"@;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@o;
;I"
overload;F;0;;g;0; I"#to_enum(method = :each, *args);T;IC;" ;T;[o;!
;I"
yield;F;I" ;T;0;[I"
*args;T;"@o;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@;#[ ;$I"(@yield [*args]
@return [Enumerator];T;%0;"@;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@o;
;I"
overload;F;0;;h;0; I"$enum_for(method = :each, *args);T;IC;" ;T;[o;!
;I"
yield;F;I" ;T;0;[I"
*args;T;"@o;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@;#[ ;$I"(@yield [*args]
@return [Enumerator];T;%0;"@;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@;#[ ;$I"\Creates a new Enumerator which will enumerate by calling +method+ on
+obj+, passing +args+ if any.
If a block is given, it will be used to calculate the size of
the enumerator without the need to iterate it (see Enumerator#size).
=== Examples
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122
# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)
It is typical to call to_enum when defining methods for
a generic Enumerable, in case no block is passed.
Here is such an example, with parameter passing and a sizing block:
module Enumerable
# a generic method to repeat the values of any enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
return to_enum(__method__, n) do # __method__ is :repeat here
sz = size # Call size and multiply by n...
sz * n if sz # but return nil if size itself is nil
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
@overload to_enum(method = :each, *args)
@return [Enumerator]
@overload enum_for(method = :each, *args)
@return [Enumerator]
@overload to_enum(method = :each, *args)
@yield [*args]
@return [Enumerator]
@overload enum_for(method = :each, *args)
@yield [*args]
@return [Enumerator];T;%0;"@;'F;)o;*;+T;,i;-i;.@N; I"static VALUE;T;/I"Qstatic VALUE
obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
VALUE enumerator, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
};T;0To;
;F;;
;;;I"Object#enum_for;F;[[@0;[[@ i;T;;h;0;[ ;{ ;IC;"6Creates a new Enumerator which will enumerate by calling +method+ on
+obj+, passing +args+ if any.
If a block is given, it will be used to calculate the size of
the enumerator without the need to iterate it (see Enumerator#size).
=== Examples
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122
# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)
It is typical to call to_enum when defining methods for
a generic Enumerable, in case no block is passed.
Here is such an example, with parameter passing and a sizing block:
module Enumerable
# a generic method to repeat the values of any enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
return to_enum(__method__, n) do # __method__ is :repeat here
sz = size # Call size and multiply by n...
sz * n if sz # but return nil if size itself is nil
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
;T;[ o;
;I"
overload;F;0;;g;0; I"#to_enum(method = :each, *args);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@e;#[ ;$I"@return [Enumerator];T;%0;"@e;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@eo;
;I"
overload;F;0;;h;0; I"$enum_for(method = :each, *args);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@e;#[ ;$I"@return [Enumerator];T;%0;"@e;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@eo;
;I"
overload;F;0;;g;0; I"#to_enum(method = :each, *args);T;IC;" ;T;[o;!
;I"
yield;F;I" ;T;0;[I"
*args;T;"@eo;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@e;#[ ;$I"(@yield [*args]
@return [Enumerator];T;%0;"@e;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@eo;
;I"
overload;F;0;;h;0; I"$enum_for(method = :each, *args);T;IC;" ;T;[o;!
;I"
yield;F;I" ;T;0;[I"
*args;T;"@eo;!
;I"return;F;I" ;T;0;[I"Enumerator;T;"@e;#[ ;$I"(@yield [*args]
@return [Enumerator];T;%0;"@e;&0;'F;(i ;[[I"method;TI"
:each;T[I"
*args;T0;"@e;#[ ;$@a;%0;"@e;'F;)o;*;+T;,i;-i;.@N; I"static VALUE;T;/I"Qstatic VALUE
obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
VALUE enumerator, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
};T;0To;
;F;;
;;;I"Object#display;F;[[@0;[[I" io.c;TiK;T;:display;0;[ ;{ ;IC;"Prints obj on the given port (default $>
).
Equivalent to:
def display(port=$>)
port.write self
end
For example:
1.display
"cat".display
[ 4, 5, 6 ].display
puts
produces:
1cat456
;T;[o;
;I"
overload;F;0;;i;0; I"display(port=$>);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"nil;T;"@;#[ ;$I"@return [nil];T;%0;"@;&0;'F;(i ;[[I" port;TI"$>;T;"@;#[ ;$I"Prints obj on the given port (default $>
).
Equivalent to:
def display(port=$>)
port.write self
end
For example:
1.display
"cat".display
[ 4, 5, 6 ].display
puts
produces:
1cat456
@overload display(port=$>)
@return [nil];T;%0;"@;'F;)o;*;+T;,i4;-iH;.@N; I"static VALUE;T;/I"static VALUE
rb_obj_display(int argc, VALUE *argv, VALUE self)
{
VALUE out;
if (argc == 0) {
out = rb_stdout;
}
else {
rb_scan_args(argc, argv, "01", &out);
}
rb_io_write(out, self);
return Qnil;
};T;0To;
;F;;
;;;I"Object#extend;F;[[@0;[[I"eval.c;Til;T;:extend;0;[ ;{ ;IC;"sAdds to _obj_ the instance methods from each module given as a
parameter.
module Mod
def hello
"Hello from Mod.\n"
end
end
class Klass
def hello
"Hello from Klass.\n"
end
end
k = Klass.new
k.hello #=> "Hello from Klass.\n"
k.extend(Mod) #=> #
k.hello #=> "Hello from Mod.\n"
;T;[o;
;I"
overload;F;0;;j;0; I"extend(module, ...);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Object;T;"@;#[ ;$I"@return [Object];T;%0;"@;&0;'F;(i ;[ ;"@;#[ ;$I"Adds to _obj_ the instance methods from each module given as a
parameter.
module Mod
def hello
"Hello from Mod.\n"
end
end
class Klass
def hello
"Hello from Klass.\n"
end
end
k = Klass.new
k.hello #=> "Hello from Klass.\n"
k.extend(Mod) #=> #
k.hello #=> "Hello from Mod.\n"
@overload extend(module, ...)
@return [Object];T;%0;"@;'F;)o;*;+T;,iS;-ii;.@N; I"static VALUE;T;/I"static VALUE
rb_obj_extend(int argc, VALUE *argv, VALUE obj)
{
int i;
ID id_extend_object, id_extended;
CONST_ID(id_extend_object, "extend_object");
CONST_ID(id_extended, "extended");
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
for (i = 0; i < argc; i++)
Check_Type(argv[i], T_MODULE);
while (argc--) {
rb_funcall(argv[argc], id_extend_object, 1, obj);
rb_funcall(argv[argc], id_extended, 1, obj);
}
return obj;
};T;0To;
;F;;
;;;I"Object#respond_to?;F;[[@0;[[I"vm_method.c;Ti;T;:respond_to?;0;[ ;{ ;IC;"Returns +true+ if _obj_ responds to the given method. Private and
protected methods are included in the search only if the optional
second parameter evaluates to +true+.
If the method is not implemented,
as Process.fork on Windows, File.lchmod on GNU/Linux, etc.,
false is returned.
If the method is not defined, respond_to_missing?
method is called and the result is returned.
When the method name parameter is given as a string, the string is
converted to a symbol.
;T;[o;
;I"
overload;F;0;;k;0; I"+respond_to?(symbol, include_all=false);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@;#[ ;$I"@return [Boolean];T;%0;"@;&0;'F;(i ;[[I"symbol;T0[I"include_all;TI"
false;T;"@o;
;I"
overload;F;0;;k;0; I"+respond_to?(string, include_all=false);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@;#[ ;$I"@return [Boolean];T;%0;"@;&0;'F;(i ;[[I"string;T0[I"include_all;TI"
false;T;"@o;!
;I"return;F;@;0;[@;"@;#[ ;$I"pReturns +true+ if _obj_ responds to the given method. Private and
protected methods are included in the search only if the optional
second parameter evaluates to +true+.
If the method is not implemented,
as Process.fork on Windows, File.lchmod on GNU/Linux, etc.,
false is returned.
If the method is not defined, respond_to_missing?
method is called and the result is returned.
When the method name parameter is given as a string, the string is
converted to a symbol.
@overload respond_to?(symbol, include_all=false)
@return [Boolean]
@overload respond_to?(string, include_all=false)
@return [Boolean];T;%0;"@;'F;)o;*;+T;,i;-i;.@N; I"static VALUE;T;/I"static VALUE
obj_respond_to(int argc, VALUE *argv, VALUE obj)
{
VALUE mid, priv;
ID id;
rb_thread_t *th = GET_THREAD();
rb_scan_args(argc, argv, "11", &mid, &priv);
if (!(id = rb_check_id(&mid))) {
VALUE ret = basic_obj_respond_to_missing(th, CLASS_OF(obj), obj,
rb_to_symbol(mid), priv);
if (ret == Qundef) ret = Qfalse;
return ret;
}
if (basic_obj_respond_to(th, obj, id, !RTEST(priv)))
return Qtrue;
return Qfalse;
};T;0To;
;F;;
;;;I"Object#respond_to_missing?;F;[[I"mid;T0[I" priv;T0;[[@i;T;:respond_to_missing?;0;[ ;{ ;IC;"DO NOT USE THIS DIRECTLY.
Hook method to return whether the _obj_ can respond to _id_ method
or not.
When the method name parameter is given as a string, the string is
converted to a symbol.
See #respond_to?, and the example of BasicObject.
;T;[o;
;I"
overload;F;0;;l;0; I"-respond_to_missing?(symbol, include_all);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@9;#[ ;$I"@return [Boolean];T;%0;"@9;&0;'F;(i ;[[I"symbol;T0[I"include_all;T0;"@9o;
;I"
overload;F;0;;l;0; I"-respond_to_missing?(string, include_all);T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@9;#[ ;$I"@return [Boolean];T;%0;"@9;&0;'F;(i ;[[I"string;T0[I"include_all;T0;"@9o;!
;I"return;F;@;0;[@;"@9;#[ ;$I"DO NOT USE THIS DIRECTLY.
Hook method to return whether the _obj_ can respond to _id_ method
or not.
When the method name parameter is given as a string, the string is
converted to a symbol.
See #respond_to?, and the example of BasicObject.
@overload respond_to_missing?(symbol, include_all)
@return [Boolean]
@overload respond_to_missing?(string, include_all)
@return [Boolean];T;%0;"@9;'F;)o;*;+T;,i;-i;.@N; I"static VALUE;T;/I"astatic VALUE
obj_respond_to_missing(VALUE obj, VALUE mid, VALUE priv)
{
return Qfalse;
};T;0To;
;F;;
;;;I"Object#nil?;F;[ ;[[I"
object.c;TiY;T;: nil?;0;[ ;{ ;IC;"Only the object nil responds true
to nil?
.
Object.new.nil? #=> false
nil.nil? #=> true
;T;[o;
;I"
overload;F;0;;m;0; I" nil?;T;IC;" ;T;[o;!
;I"return;F;I" ;T;0;[I"Boolean;T;"@p;#[ ;$I"@return [Boolean];T;%0;"@p;&0;'F;(i ;[ ;"@po;!
;I"return;F;@;0;[@;"@p;#[ ;$I"Only the object nil responds true
to nil?
.
Object.new.nil? #=> false
nil.nil? #=> true
@overload nil?
@return [Boolean];T;%0;"@p;'F;)o;*;+T;,iN;-iU;.@N; I"static VALUE;T;/I"