Reputation: 1529
One syntax I am not able to understand is like this:
test = heavy::Test.new_test()
test.setq(name)
Here test
is an object and in some other file there is module heavy
and inside heavy
there is another module Test
but after that what is this new_test()
?
Upvotes: 1
Views: 10504
Reputation: 47472
class Heavy
end
class Test < Heavy
def self.new_test #This is class method (Written as self.method_name or model_name.method_name)
puts "Hello World"
end
def setq(name) #this is instance method (Call on object of a class not as class method)
puts "Hello "+name
end
end
test = Heavy::Test.new_test() # print 'Hello World'
test.setq('Salil') #print 'Hello Salil'
class/module name must be CONSTANT (1st letter should be capital) (i.e.heavy should be Heavy)
Upvotes: 2