lib/knj/os.rb in knjrbfw-0.0.29 vs lib/knj/os.rb in knjrbfw-0.0.30

- old
+ new

@@ -1,6 +1,9 @@ module Knj::Os + #Returns the path of the home-dir as a string. + #===Examples + # print "Looks like the current user uses Mozilla software?" if File.exists?("#{Knj::Os.homedir}/.mozilla") def self.homedir if ENV["USERPROFILE"] homedir = ENV["USERPROFILE"] else homedir = File.expand_path("~") @@ -12,10 +15,12 @@ return homedir end #This method was created to make up for the fact that Dir.tmpdir sometimes returns empty strings?? + #===Examples + # tmp_db_path = "#{Knj::Os.tmpdir}/temp_db.sqlite3" def self.tmpdir require "tmpdir" tmpdir = Dir.tmpdir.to_s.strip return tmpdir if tmpdir.length >= 3 and File.exists?(tmpdir) @@ -24,10 +29,13 @@ return "/tmp" if File.exists?("/tmp") raise "Could not figure out temp-dir." end + #This method returns the username of the current user. + #===Examples + # print "I can do what I want, I am root!" if Knj::Os.whoami == "root" def self.whoami if ENV["USERNAME"] whoami = ENV["USERNAME"] else whoami = %x[whoami].strip @@ -38,9 +46,13 @@ end return whoami end + #Returns the operating system a string. + #===Examples + # print "Can I please move to another machine?" if Knj::Os.os == "windows" + # print "I like it better now." if Knj::Os.os == "linux" def self.os if ENV["OS"] teststring = ENV["OS"].to_s elsif RUBY_PLATFORM teststring = RUBY_PLATFORM.to_s \ No newline at end of file