Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Etc.passwd

() { (::Etc::Passwd passwd) -> void } -> void
() -> ::Etc::Passwd?
passwd { |struct| block }
passwd → Etc::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.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0