Question: This is for a homework problem, so I tried to work through it as much as I could before coming here for help. I've got it 95% solved, I just can't figure out the syntax of the last bit or what method I should be using if it's different from what I'm doing now. I can't find any solution to this online that isn't actually my classmates' answers and I'm avoiding clicking on those to see how they completed the problem.

I can return the string without formatting if it only has one element, with only the word 'and' when there are two elements, and I can add commas and the word 'and' when there are more than three elements. However, I can't seem to skip adding the last comma when the array has more than three elements.

```
def oxford_comma(array)
    if array.length == 2
        array.join(" and ")
    elsif array.length > 2
        array.insert(-2, "and")
        array[0..-1].join(", ")
    else
        array.join
    end
end

```

Here's the error message I'm getting:

```
         Failure/Error: expect(oxford_comma(["kiwi", "durian", "starfruit", "mangos", "dragon fruits"])).to eq("kiwi, durian, starfruit, mangos, and dragon fruits")

   expected: "kiwi, durian, starfruit, mangos, and dragon fruits"
        got: "kiwi, durian, starfruit, mangos, and, dragon fruits"

   (compared using ==)

```

Answer: 
When you have just one element in the array, [Array#join](https://ruby-doc.org/core-2.6.3/Array.html#method-i-join) returns the element itself:

```
['a'].join(' and ') #=> "a"

```

So, you could simplify your code prepending `"and "` to the last element when list size is 3 or more or returning `.join(' and ')` if less than 3 elements:

```
def oxford_comma(list)
  return list.join(' and ') if list.size < 3
  list[-1] = "and " + list[-1]
  list.join(', ')
end

```
EDIT with max comments:

You can do that:

```
def oxford_comma(array)
  array = [*array]
  case array.size
  when 0
    ''
  when 1
    array[0].to_s
  when 2
    array.join(' and ')
  else
    array_copy = array
    array_copy[-1] = "and #{array_copy[-1]}"
    array_copy.join(', ')
  end
end

```

The case when is to handle edge cases for empty array, single value array and double values array.
Otherwise, you change the last item to add the `and` then join everything with comma.
Use a copy of the array to be non destructive.

[![enter image description here](https://i.stack.imgur.com/nkKUr.png)](https://i.stack.imgur.com/nkKUr.png)