Archive for February 23rd, 2008

strongly typed language

Statically typed language :: the type of a variable can not be altered.
int x;
x = 420;
x = “Mr. Bechara”;  # Error
Dynamically typed language  :: the type of a variable can be altered at any time.
x = 420
x = “Common I am a good person”
x = :intelligent_person
x = /regular ex form/

Strongly typed language :: strict about what you can do with your typed variables.
On mixing, it will see I am hugging a beauty or a bitch.

You smells like a rose
x = “14″
y = x + “February” #”14February
The stinking ….
x = “Decemebr”
y = x + 1             # Error

Weakly typed language ::play a show definitely for your typed variable. I meant for lust not love.

x = myfunction_returns_5();
y = x + 1 // Ya give me 6 , damn!! it has given me 51

Ruby : Dynamically, strongly
Javascript : Dynamically, weakly
C,C++ : Statically

Ref: blog of “rubyfleebie:Frank”

Add comment February 23, 2008

class methods

What is a class method ?
- A class method resides at the class level.
- An instance method resides at the object level.

Class level – basically means such methods are associted with class, rather than being with object directly.

How can we define such class methods?
In there ways:

  1. Using classname.classmethod_name
  2. Using self.classmethod_name
  3. Defined your method as

class << self
def classmethod_name
end
end

How can we call such methods?
Classname.classmethod_name

Note:
> You can use the self variable, which is always pointing to the current object
> For creating the anonymous class(class having no name), we use the << notation.

class Myclass
def Myclass.class_method1
p “Its a class method using class name”
end

def self.class_method2
p “Its another class method using self”
end

class << self
def class_method3
p “This too using class<<self”
end
end
end

Myclass.class_method1
Myclass.class_method2
Myclass.class_method3

# “Its a class method using class name”
# “Its another class method using self”
# “This too using class<<self”

How to access a class method from an instance (using object) ?
<instance_name>.class.<class_method_name>

class Myclass
def Myclass.class_method
p “Called using an instance of Myclass i.e obj”
end
end
obj = Myclass.new
obj.class.class_method

o/p
Called using an instance of Myclass i.e obj

Add comment February 23, 2008


@@name=PRAYAS

gap_resize.jpg

Time.now()

February 2008
M T W T F S S
    Mar »
 123
45678910
11121314151617
18192021222324
2526272829  

order[:category]

posts[:recent]

episodes[:recycled]

links[:favourite]

vote_for_web2.0

Step down at my blog with your ideas,comments,suggestions on Ruby,RoR,Ajax or Web2.0 Technology. You may reach me at rajesh4it@gmail.com.

@visitors.count(Feb’08)

find_all(:categories)

Around me bollywood coding news@RoR Rails RoR Ruby Tools&Tips Web2.0 talks

Vote for RoR

Blog Stats