From: Robert Klemme Date: 2008-03-06T23:43:25+09:00 Subject: Re: Ruby Basics / define met;hod 2008/3/6, Chinna Karuppan : > I am new to Ruby and This is a very basic question.when I type p self in > irb it gives me 'main'. Correct. > when I say class what is happening in the backend.since within a class > end I am able to call define_method which is a private method and should > never be available to anybody and another intersting thing is it is not > accessible outside of the class. irb(main):001:0> class Foo irb(main):002:1> p [self,self.class] irb(main):003:1> end [Foo, Class] => nil irb(main):004:0> Inside a class body /self/ is the class instance being defined right now. > so my question is how is a private method accessible outside > what is happening when a class is defined. First of all, inside "class...end" you are not "outside". Second, if you want to access any private method you can do so via send: irb(main):004:0> class Foo irb(main):005:1> private irb(main):006:1> def bar()123 end irb(main):007:1> end => nil irb(main):008:0> Foo.new.bar NoMethodError: private method `bar' called for # from (irb):8 from :0 irb(main):009:0> Foo.new.send :bar => 123 > it is of type Class > automatically...I don't quite get it. > As soon as you start IRB a main object is created which is of type > Object.is it is right statement... I do not know what you mean by your last sentence. "main" is of type Object - but it has some methods added: $ irb irb(main):001:0> puts class< nil irb(main):002:0> Kind regards robert -- use.inject do |as, often| as.you_can - without end