From: Robert Klemme Date: 2010-10-28T16:08:17+09:00 Subject: Re: Defining nested Method in single class On Thu, Oct 28, 2010 at 8:57 AM, Arun Kumar wrote: > Hi All, > >  Today morning i exploring the ruby 1.8.7, i found myself some what > clear so > that i worked some basic code concepts (class and methods) and i > satisfied, Again I build a > code to confuse myself. Initially it show some error, finally i made > some > modification on the code,and it works fine, but i thought it needs to > show error, can anyone please explain how it works ? > > Note: > ===== > I created a class in class it showing Error like "class definition in > method body", If its is means, why not in methods ? > > Code: > ===== > > class AdavanceConfuse >  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 >    class_method2 >  end > >  def AdavanceConfuse.class_method2 >    #~ class TestClass >      puts "this is class_method2" >      def Instance_method1 >        puts "this is instance_method1" >      end >    #~ end >  end > end > > AdavanceConfuse.Class_method1 > AdavanceConfuse.class_method1_attribute_class_method > AdavanceConfuse.class_method2 > AdavanceConfuse.new.Instance_method1 > > Output: > ======= > this is class_method1 > this is class_method2 > this is class_method1_attribute_class_method > this is class_method2 > this is instance_method1 What error did you expect to see from this - and why? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/