Thursday, June 23, 2011

Ruby constants and variables

foobar 
A variable whose name begins with a lowercase letter (a-z) or underscore (_) is a local variable.

@foobar
A variable whose name begins with '@' is an instance variable of self.

@@foobar
A class variable is shared by all instances of a class.

$foobar
A variable whose name begins with '$' has a global scope; meaning it can be accessed from anywhere within the program during runtime.

FOOBAR
A variable whose name begins with an uppercase letter (A-Z) is a constant. A constant can be reassigned a value after its initialization, but doing so will generate a warning,

More detailed information about Ruby constants and variables can be found from here:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Variables_and_Constants

Thursday, June 16, 2011

Browser version

How to get browser version e.g.

$browserversion = $ie.document.invoke('parentWindow').navigator.appVersion
            $tmp_str =/MSIE\s(.*?);/.match($browserversion)
            $browserversion = "MSIE " + $tmp_str[1] 
puts "Browser: " + $browserversion

Changing browser settings

 You can modify browser settings by using Windows Registry Editor e.g.
  
system("echo Windows Registry Editor Version 5.00 > useragent.reg") 
system("echo. >> useragent.reg")     
system("echo [HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\5.0\\User Agent] >> useragent.reg")
system("echo \"Compatible\"=\"Testclient\" >> useragent.reg")      system("regedit /s useragent.reg")   
system("del /f useragent.reg")