Tuesday, May 29, 2012

Global variable in Ruby/JRuby

If anybody wants to create a global variable which can be access to all the ruby class and module through out the project. then follow the example given below:

$globalvariable=

class
   .
   .
   .

end


The value of the globalvariale can be access through out the ruby project.

i.e. puts($globalvariable)

NOTE: "$globalvariable=value" may be display as $globalvariable= . it is a Bug with Blogger. So read it as  "$globalvariable=value"

Monday, May 28, 2012

Log Redirection in Ruby

If you wan to redirect your methods log to a file instead of console and after writing the log to the file the output should back to console then follow the below instructions.

def example()
 oldout=$stdout
 $stdout=File.new("",'a')
.
.
.                   
.
.
$stdout=oldout
end


you can change the type of writing to log file with replace of 'w', 'w+' etc.. depends on your requirements.

Monday, April 16, 2012

Module Example in Ruby Language

The below given example guide you , how to work with ruby module.

1) The ruby module are just like ruby class , which can contain the methods , fields etc..
2) Multiple modules can possible in a file , lets take an example :

create a file testModule.rb , create it any where does not matter. In side the file create the module viz.
here we have created two modules

1)Test
2)Test1

Test contains a simple method as show , So that we can call this method just by using the object of the used class of this module Test

Test1 contains the same method , but the declaration is bit different that is Test1.show . which behaves like a static method, and you have to call this method using the Module name i.e.

"Test1.show" -----------------------------------------------------------------------------------------------------------
File :  testModule.rb
------------------------------------------------------------------------------------------------------------

module Test
    def show
        print "From method Show"
    end
end

module Test1
     def Test1.show
         print " From Method Show from Module Test1"
     end
end

------------------------------------------------------------------------------------------------

Now create another ruby file for ruby class , let demo.rb
------------------------------------------------------------------------------------------------
require File.dirname("File path ")+"/ testModule"

class Demo
include Test
include Test1

   def  demoMethod
      print " from demoMethod"
       Test1.show
   end

end

test=Demo.new
test.demoMethod
test.show


Description : "require" is the keyword which is similar to include and import in c/c++ and java

The required keyword search for the file from $LOAD_PATH , if not not found , there would be a error as file not found, So in this case you can give the file path name followed by the file name.

Test1.demo is just similar as static method call using class name reference in java

If the module name is not used before the method name at the time of defining it, then that method can be called using the used call object. here in the above example it is Demo and test is the object of the Demo class.


Tuesday, March 20, 2012

Tutorials on ruby

The most intresting language after java is ruby , may be something more than java. Honestly I do not want to hurt the java developer anyway. Here is a below sample program which will give you a sample IDEA of ruby language. It is really a pure object oriented language.

class TestClass
 @@fname=""
 @@lname=""
 @@val="Bhubaneswar"
 
 def initialize(fname,lname)
  @fname=fname
  @lname=lname
 end

 def testMethod(val)
  puts("Inside the Method")
  puts("The Global Value is '#{@fname}' and '#{@lname}'")
  @val=val
  puts("The Local Value is '#{@val}'")
  puts("The Local Value is '#{@@val}'")
 end
end
obj=TestClass.new("khirod","Patra")
obj.testMethod("Delhi")


Description: TestClass is the name of the class must be stared with a capital letter. @@fname,@@lname,@@val are the class variable. The class variab;e declared with @@ symbol and the instance variable declared with single @ symbol. In the method testMethod you can see the instance variable i.e. @val . So if you want to access the class variable or the instance variable , you have to prefix with @@ or @ symbol with variable name, Incase if you have same variable name

Questions are welcome...

Friday, November 12, 2010

Tips on Virtual Box

If you are using any Virtual box , then you mustt add your user name to the vboxgusers group, So that you get access to the USB system in Windows XP i.e.

usermod -A vboxusers

Sunday, July 18, 2010

Install Oracle 10g XE on ubuntu

1) download oracle  oracle-xe-universal_10.2.0.1-1.0_i386.deb from the oracle official website


Then

sudo dpkg -i oracle-xe-universal_10.2.0.1-1.0_i386.deb



2) sudo /etc/init.d/oracle-xe configure

It will ask the value for some option like

Specify the HTTP port that will be used for Oracle Application Express [8080]:7070


By default the port number is 8080, be care full make sure the same port is not used by any other process, In my case tomcat is already on 8080 so i changed to 7070.

Similarly :
Specify a port that will be used for the database listener [1521]:1521

Then Specify the Password and confirm password  and restart the datatabase like

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of
different passwords for each database account.  This can be done after
initial configuration:
Confirm the password:

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:y








It Will restart the oracle and now oracle ready to use

You can try it from SQL command line or from http://127.0.0.1:7070/apex

In the above link change the port number accordingly ,what ever you mentioned in the configuration file

from the command line  of SQL, give the command
connect system/manager   i.e

Note: The default database name of 10g is xe.

Tuesday, July 6, 2010

Size of a Symbolic Link In UNIX

Check the Below Example:

lrwxrwxrwx 1 root root 8 Dec 8 2008 swbt -> /nas/usr
lrwxrwxrwx 1 root root 10 Dec 5 2008 tmp -> ../var/tmp

In the above llinks the sizes are 8 and 10 respectively . The Symbolic calculate the size according to the
number of the charaters in the link Path i.e

/nas/usr has 8 characters So the Size is 8

../var/tmp has 10 character So the Size is 10