Just add your code directly to the class body:
class MyClass @my_var = 'init1' my_method 'init2' def self.my_method(param) end end
This code will be called when the class is loaded.
PS: If you are working on a Rails project, you may already be familiar with this concept:
class MyModel < ActiveRecord::Base has_many belongs_to validates scope end
All of these methods are executed at the class level.
source share