Class: Snackhack2::ListUsers
- Inherits:
-
Object
- Object
- Snackhack2::ListUsers
- Defined in:
- lib/snackhack2/list_users.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #auto ⇒ Object
-
#initialize(user) ⇒ ListUsers
constructor
A new instance of ListUsers.
- #linux ⇒ Object
- #windows ⇒ Object
- #windows_search_user ⇒ Object
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
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/snackhack2/list_users.rb', line 5 def user @user end |
Instance Method Details
#auto ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/snackhack2/list_users.rb', line 27 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 |
#linux ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/snackhack2/list_users.rb', line 11 def linux # uses the cat file to read the users in /etc/passwd # then displays all the users `cat /etc/passwd`.split("\n").each do |l| puts l.split(':')[0] end end |
#windows ⇒ Object
19 20 21 |
# File 'lib/snackhack2/list_users.rb', line 19 def windows puts `net users` end |
#windows_search_user ⇒ Object
23 24 25 |
# File 'lib/snackhack2/list_users.rb', line 23 def windows_search_user puts `net user #{@user}` end |