instance method
sole
Ruby on Rails edge
Since v7.2.4Signature
sole()
Returns the sole item in the range. If there are no items, or more than one item, raises Enumerable::SoleItemExpectedError.
“‘ruby (1..1).sole # => 1 (2..1).sole # => Enumerable::SoleItemExpectedError: no item found (..1).sole # => Enumerable::SoleItemExpectedError: infinite range cannot represent a sole item “`
Source
# File activesupport/lib/active_support/core_ext/range/sole.rb, line 14
def sole
if self.begin.nil? || self.end.nil?
raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "infinite range '#{inspect}' cannot represent a sole item"
end
super
end
Defined in activesupport/lib/active_support/core_ext/range/sole.rb line 14
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Range