tags:

views:

68

answers:

1

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()?

A: 
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)

Salil
No, there is no method named new_test in my code .thats is my problem.there is no such thing and heavy and Test are module is it create any prob
Amit singh tomar
but gishu this new_test is nowhere used as a method
Amit singh tomar
Then it is the method of a super class of test module which is directly accessible to the test. please paste the code of heavy as well as Test
Salil
what do u mean by method of a super class of test module which directy accessible to the test
Amit singh tomar