1
0

More than 1 year has passed since last update.

[Ruby] Integerクラスのabsメソッド

Posted at

学習したことのアウトプットとして

absメソッド

Rubyの組み込みライブラリ
対象となる数値に対してabsメソッドを実行すると絶対値を取得することができる。すなわち正の数の場合はそのままだが、負の数の場合は符号を取って正の数にした数値が取得できる。

num = 5.abs
#=> 5

num = (-5).abs
#=> 5

absメソッドのリファレンス

以上。

※補足等ありましたらコメントいただけると幸いです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0