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
ext/etc/etc.c
View on GitHub ↗
static VALUE
etc_passwd(VALUE obj)
{
#ifdef HAVE_GETPWENT
struct passwd *pw;
if (rb_block_given_p()) {
each_passwd();
}
else if ((pw = getpwent()) != 0) {
return setup_passwd(pw);
}
#endif
return Qnil;
}
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 }