Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Etc::Passwd.each

Etc::Passwd.each { |struct| block } → Passwd
Etc::Passwd.each → Enumerator

Iterates for each entry in the /etc/passwd file if a block is given.

If no block is given, returns the Enumerator.

The code block is passed an Passwd struct.

See Etc.getpwent above for details.

Example:

Example
require 'etc'

Etc::Passwd.each {|u|
  puts u.name + " = " + u.gecos
}

Etc::Passwd.collect {|u| u.gecos}
Etc::Passwd.collect {|u| u.gecos}
also in 4.1 · 4.0 · 3.4 · 3.3