Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Includes:
- Comparable
- Defined in:
- mrblib/numeric.rb,
mrbgems/mruby-complex/mrblib/complex.rb,
mrbgems/mruby-rational/mrblib/rational.rb,
mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb
Overview
Numeric
ISO 15.2.7
Instance Method Summary collapse
-
#+@ ⇒ Object
Returns the receiver simply.
-
#-@ ⇒ Object
Returns the receiver's value, negated.
-
#abs ⇒ Object
Returns the absolute value of the receiver.
-
#integer? ⇒ Boolean
call-seq: num.integer? -> true or false.
-
#negative? ⇒ Boolean
call-seq: negative? -> true or false.
-
#nonzero? ⇒ Boolean
call-seq: nonzero? -> self or nil.
-
#positive? ⇒ Boolean
call-seq: positive? -> true or false.
- #to_c ⇒ Object
- #to_r ⇒ Object
-
#zero? ⇒ Boolean
call-seq: zero? -> true or false.
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?, #clamp
Instance Method Details
#+@ ⇒ Object
Returns the receiver simply.
ISO 15.2.7.4.1
11 12 13 |
# File 'mrblib/numeric.rb', line 11 def +@ self end |
#-@ ⇒ Object
Returns the receiver's value, negated.
ISO 15.2.7.4.2
19 20 21 |
# File 'mrblib/numeric.rb', line 19 def -@ 0 - self end |
#abs ⇒ Object
Returns the absolute value of the receiver.
ISO 15.2.7.4.3
27 28 29 30 31 32 33 |
# File 'mrblib/numeric.rb', line 27 def abs if self < 0 -self else self end end |
#integer? ⇒ Boolean
call-seq: num.integer? -> true or false
Returns true if num is an Integer.
1.0.integer? #=> false 1.integer? #=> true
59 60 61 |
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 59 def integer? false end |
#negative? ⇒ Boolean
call-seq: negative? -> true or false
Returns true if self is less than 0, false otherwise.
46 47 48 |
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 46 def negative? self < 0 end |
#nonzero? ⇒ Boolean
call-seq: nonzero? -> self or nil
Returns self if self is not a zero value, nil otherwise;
uses method zero? for the evaluation.
22 23 24 25 26 27 28 |
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 22 def nonzero? if self == 0 nil else self end end |
#positive? ⇒ Boolean
call-seq: positive? -> true or false
Returns true if self is greater than 0, false otherwise.
36 37 38 |
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 36 def positive? self > 0 end |
#to_c ⇒ Object
86 87 88 |
# File 'mrbgems/mruby-complex/mrblib/complex.rb', line 86 def to_c Complex(self, 0) end |
#to_r ⇒ Object
19 20 21 |
# File 'mrbgems/mruby-rational/mrblib/rational.rb', line 19 def to_r Rational(self, 1) end |
#zero? ⇒ Boolean
call-seq: zero? -> true or false
Returns true if zero has a zero value, false otherwise.
Of the Core and Standard Library classes, only Rational and Complex use this implementation.
11 12 13 |
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 11 def zero? self == 0 end |