Method: Array#after
- Defined in:
- lib/core/facets/array/before.rb
#after(value) ⇒ Object
Returns the value after the given value. The value before the last is the first. Returns nil if the given value is not in the array.
Examples
sequence = ['a', 'b', 'c']
sequence.after('a') #=> 'b'
sequence.after('b') #=> 'c'
sequence.after('c') #=> 'a'
sequence.after('d') #=> nil
CREDIT: Tyler Rick
35 36 37 38 |
# File 'lib/core/facets/array/before.rb', line 35 def after(value) return nil unless include? value self[(index(value).to_i + 1) % length] end |