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:
- Using classname.classmethod_name
- Using self.classmethod_name
- 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
