Near Near - 6 months ago 21
Ruby Question

Calling method within Class

im new in ruby so this code is not working, please provide me the proper way of calling a method within class

Class TestClass

def testMethod
puts "hello"
end

testMethod
end


UPDATE

hi everyone thanks for all the help and comments just like @Stefan and @Matt said, my example is very uncommon to use this way and thanks for giving the right path anyway i just want to add this from my question and i found a way to work

class TestClass
def self.testMethod
puts "hello"
end

TestClass.testMethod
end

Answer
class TestClass
    # a class method
    def self.test_method
       puts "Hello from TestClass"
    end

    # an instance method
    def test_method
       puts "Hello from an instance of TestClass"
    end
 end

 # call the class method
 TestClass.test_method


 # create and instance object of TestClass
 instance_of_TestClass = TestClass.new

 # call the instance method of the new object
 instance_of_TestClass.test_method