summaryrefslogtreecommitdiffhomepage
path: root/mrblib/numeric.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-10-22 15:59:41 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2013-10-22 15:59:41 +0900
commit620f8b2721e2bf05b610116cc3857a87b6c140e6 (patch)
tree4f66534881d39c339071d8e4a7ff04a0a810c973 /mrblib/numeric.rb
parent3ae0616710b10b091baa130f85a56b5ef2c66633 (diff)
downloadmruby-620f8b2721e2bf05b610116cc3857a87b6c140e6.tar.gz
mruby-620f8b2721e2bf05b610116cc3857a87b6c140e6.zip
implement some Numeric methods in Ruby
Diffstat (limited to 'mrblib/numeric.rb')
-rw-r--r--mrblib/numeric.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index a5aa3e451..f3f1a2a7e 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -1,4 +1,38 @@
##
+# Numeric
+#
+# ISO 15.2.7
+class Numeric
+ ##
+ # Returns the receiver simply.
+ #
+ # ISO 15.2.7.4.1
+ def +@
+ self
+ end
+
+ ##
+ # Returns the receiver's value, negated.
+ #
+ # ISO 15.2.7.4.2
+ def -@
+ 0 - self
+ end
+
+ ##
+ # Returns the absolute value of the receiver.
+ #
+ # ISO 15.2.7.4.3
+ def abs
+ if self < 0
+ -self
+ else
+ self
+ end
+ end
+end
+
+##
# Integer
#
# ISO 15.2.8