Ruby provides an ‘etc’ class designed to interface with /etc directory on Unix like systems. This can provide more information than traditional $user or $home variable calls.

>> require 'etc'
>> Etc.sysconfdir()
=> "/Users/username/.rbenv/versions/2.0.0-p247/etc"

or

login = Etc.getlogin
info = Etc.getpwnam(login)
=> #<struct Struct::Passwd name="username", passwd="********", uid=501, gid=20, gecos="BrettU", dir="/Users/username", shell="/bin/zsh", change=0, uclass="", expire=0>

Boom, a ton of system user info without leaving your Ruby app.

:)

Leave a Reply

Your email address will not be published. Required fields are marked *