4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ruby]値が範囲内に存在するかbetweenでチェック(数、文字、日付)

Posted at

参考:知って得する!55のRubyのトリビアな記法

範囲内にあるかどうかは、between?でチェックできる。

Comparableモジュールをインクルードしている
数(Numeric)、
文字(String),
シンボル(Symbol)、
日付(Time)、
で利用できる。:grapes:

48.between?(0, 50)
# => true

'D'.between?('A', 'C')
# => false

:b.between?(:a, :d)
# => true

now = Time.now
now.yesterday.between?(now.prev_week, now.next_week)
# => true
4
6
2

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
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?