Hi Readers,
In this post you are going to learn how to define class methods and how to call those methods.
If you want to define a class method there are two ways.
1. Inside the class by using the self keyword
2. Inside the class by using "class << self"
Refer the below example to get the Info.
class Person
def self.class_method
puts "class method invoked"
end
class << self
def class_method2; puts "class_method2"; end
def class_method3; puts "class_method3"; end
end
end
class << Person
def class_method4; puts "class_method4"; end
end
# Invocation of class method
Person.class_method
Just practice this, i will come back with new concept.
To get more updates subscribe and follow my blog.
Thank you
No comments:
Post a Comment