Check the range belongings : Range include « Range « Ruby






Check the range belongings


c = -2..2
c.all? {|x| x>0}    # => false: not all values are > 0
c.any? {|x| x>0}    # => true: some values are > 0
c.none? {|x| x>2}   # => true: no values are > 2
c.one? {|x| x>0}    # => false: more than one value is > 0
c.one? {|x| x>2}    # => false: no values are > 2
c.one? {|x| x==2}   # => true: one value == 2
[1, 2, 3].all?      # => true: no values are nil or false
[nil, false].any?   # => false: no true values
[].none?            # => true: no non-false, non-nil values

 








Related examples in the same category

1.Test if something is included in the set of objects specified by the range.
2.Being a lowercase letter
3.is an integer in a range
4.is an integer in an exclusive range
5.Range containability check
6.Range pattern match