Folks, I am learning ruby and recently moved from JAVA. In JAVA I could make a member variable of a class static and that member variable would remain the same across instances of the class. How do I achieve the same in ruby. I did something like this in my ruby class:
class Baseclass
@@wordshash
end
This seems to serve the purpose so far while I am testing this, that is @@wordhash remains the same across instances of Baseclass. Is my understanding correct.
Also, I wanted to have a member method in the class that is equivalent of a static method in JAVA(I do not require to have an instance of the class to access this). How can I do this? For example I want to have a method in the Baseclass like getwordshash() which returns @@wordshash and the user of that method should not have to make an instance of Baseclass().So something like this:
class Baseclass
@@wordshash
#static or class method
def getwordhash()
return @@wordshash
end
end
and then I can use it like
#without making an instance
@hash = Baseclass.getwordhash()
I apologize if this is a very naive question, i am really new to ruby but very excited to learn.