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
33 34 35 36 |
# File 'lib/core/facets/array/before.rb', line 33 def after(value) return nil unless include? value self[(index(value).to_i + 1) % length] end |