Question: I can only find methods that look for specific elements of an array.

During my objects.each |a| loop, I want to know when I'm at the final element so I can have a loop like:

```
objects.each |a|
   if objects.hasNext()
       puts a.name + ","
   else
       puts a.name

```

Iterator's hasNext() determines if the Array's iterator has another element after the one currently being evaluated.

I want to emphasize that I'm looking to print out these values, not turn them in to an Array. .join is not what I'm looking for here.

Answer: 
No, there isn't. However, note that `hasNext` is not an `Array` operation in Java, either. It's an `Iterator` operation, and Ruby's equivalent to Java's `Iterator` is `Enumerator`, not `Array`.

However, Ruby's `Enumerator` works a little bit different than Java's: instead of asking whether there is a next element, and then advancing the iterator, you simply try to look at the next element and it throws a `StopIteration` exception when there are no more elements.

So, the equivalent to Java's

```
iter.hasNext);

```

would be roughly

```
begin
  enum.peek
  true
rescue StopIteration
  false
end

```

However, you almost *never* iterate manually in Ruby. Instead, you use higher-level iteration methods such as `join`, `flat_map`, `group_by`, `uniq`, `sort`, `sort_by`, `inject`, `map`, `each_with_object`, `each` etc.

For example:

```
%w(pretty ugly stupid).join(', ') # => 'pretty, ugly, stupid'

```
In the Ruby library iterators are implemented as internal iterators in contrast to Java which implements external iterators. The key difference between the two is that the former are designed to not let the client control the iteration, while the latter leave to the client this responsibility. 

The purpose of a method like `hasNext` is to control iteration directly, thus in Ruby no such thing exists. Methods like `peek` and `next` defined by `Enumerator` are, I guess, not intended to control iteration directly but to implement custom internal iterators.

That said, your problem is easily solved with this code:

```
puts objects.map(&:name).join(', ')

```

However sometimes could be useful to concoct your own internal iterator using an `Enumerator` object:

```
module Enumerable
  def puts_each_with_separator(separator)
    enum = each
    loop do
      print yield(enum.next)
      enum.peek rescue break
      print separator
    end
    puts
  end
end

objects.puts_each_with_separator(', ', &:name)

```