ruby array remove last element code example
Example 1: ruby remove value from array
# Altering the array:
a = [3, 2, 4, 6, 3, 8]
a.delete(3)
#=> 3
a
#=> [2, 4, 6, 8]
# Creating new array:
b = [3, 2, 4, 6, 3, 8]
b - [3]
#=> [2, 4, 6, 8]
b
#=> [3, 2, 4, 6, 3, 8]
Example 2: ruby remove last element of string
'abc1234'.chomp(4) # => 'abc123'
'toto'.chomp('to') # => 'to'
Example 3: delete item from array in ruby
a = [3, 2, 4, 6, 3, 8]
a.delete(3)