Method: LinuxStat::User.username_by_gid
- Defined in:
- lib/linux_stat/user.rb
.username_by_gid(gid = get_gid) ⇒ Object
username_by_gid(gid = get_gid)
Where gid is the group id of the user. By default it’s the gid of the current user.
It returns a String cotaining the username corresponding to the gid
But if the info isn’t available it will return an empty frozen String.
190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/linux_stat/user.rb', line 190 def username_by_gid(gid = get_gid) return ''.freeze unless passwd_readable? username = ''.freeze passwd.each do |x| splitted = x.split(?:.freeze) if splitted[2].to_i == gid username = splitted[0] break end end username end |