Class: Snackhack2::ListUsers

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/list_users.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ ListUsers

Returns a new instance of ListUsers.



7
8
9
# File 'lib/snackhack2/list_users.rb', line 7

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/snackhack2/list_users.rb', line 5

def user
  @user
end

Instance Method Details

#autoObject



25
26
27
28
29
30
31
32
# File 'lib/snackhack2/list_users.rb', line 25

def auto
  os = RUBY_PLATFORM
  if os.match?('linux')
    linux
  elsif os.match?('mingw') || os.match?(/mswin|msys|mingw|cygwin|bccwin|wince|emc/)
    windows
  end
end

#linuxObject



11
12
13
14
15
# File 'lib/snackhack2/list_users.rb', line 11

def linux
  `cat /etc/passwd`.split("\n").each do |l|
    puts l.split(':')[0]
  end
end

#windowsObject



17
18
19
# File 'lib/snackhack2/list_users.rb', line 17

def windows
  puts `net users`
end

#windows_search_userObject



21
22
23
# File 'lib/snackhack2/list_users.rb', line 21

def windows_search_user
  puts `net user #{@user}`
end