Tuesday, October 26, 2010

Hello to RubyMine

As part of starting my adventures in Ruby, I thought an IDE is essential and so settled with RubyMine (on a 30 day trial.) As my first program in ruby I just wanted to print "Hello World" from a static method.

The trick to use was keyword self. The scope of self varies depending on the context. Inside an instance method, self resolves to the receiver object. Outside an instance method, but inside a class definition, self resolves to the class.

class Hello
  def self.SayHello()
    puts "Hello World"


And self is not the only way to create class methods. Here is a list of more.

No comments: