Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Etc.passwd

Etc.passwd { |struct| block } → Passwd
Etc.passwd → Passwd

Provides a convenient Ruby iterator which executes a block for each entry in the /etc/passwd file.

The code block is passed an Passwd struct.

See ::getpwent above for details.

Example:

Example
require 'etc'

Etc.passwd {|u|
  puts u.name + " = " + u.gecos
}
See also .nprocessors .setgrent .group .setpwent also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0