From: Robert Klemme Date: 2010-10-28T17:30:44+09:00 Subject: Re: Defining nested Method in single class On Thu, Oct 28, 2010 at 9:28 AM, Arun Kumar wrote: > I created a class with in class it showing Error like "class definition > in method body", > """""""""""If its is means, why not in methods ?""""""""""" That's just the way it is: you can define nested methods in a method. The feature isn't too useful though. If you want to define a class in a method (beware, it happens every time the method is called!) you can do def foo Class.new do def bar; 123; end end end irb(main):006:0> foo.new => #<#:0x10153d14> irb(main):007:0> foo.tap {|cl| p cl; cl.new.bar} # => # irb(main):008:0> foo.tap {|cl| p cl; cl.new.bar} # => # > 1. May be my question is wrong ? can u please tell me how to call method > defined within method of class ? You know it already, don't you? Please look at your code. >  """"" >        def AdavanceConfuse.Class_method1 >    puts "this is class_method1" >    def AdavanceConfuse.class_method1_attribute_class_method >      puts "this is class_method1_attribute_class_method" >    end >  end > """""" > > How to call the class_method1_attribute_class_method in the above code > and how it internally ,the request will be handled in ruby ? It's just defined and called like any other class method. The only difference with nested definitions is the point in time when the method is created (i.e. not when the interpreter executes the class definition but when someone calls the method containing the definition). > 2. How i can access a class' method defined with in class ? See above. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/