Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Integer | odd?

概要

Integer#odd?

詳細

数値が奇数か判定します。

サンプルコード
# encoding: utf-8

(1..10).each { |v| puts "#{v} is odd? :#{v.odd?} " }
出力
1 is odd? :true 
2 is odd? :false 
3 is odd? :true 
4 is odd? :false 
5 is odd? :true 
6 is odd? :false 
7 is odd? :true 
8 is odd? :false 
9 is odd? :true 
10 is odd? :false