The greet method is a private method of Object not of MyClass.
So it seems that the def in the block is evaluated in the toplevel scope
(where the block is defined) and not in the MyClass scope.

2011/3/11 7stud -- <bbxx789_05ss / yahoo.com>

> Here is some code that works as expected:
>
> def create_class
>  Class.new
> end
>
> MyClass = create_class
>
> MyClass.class_eval do
>  def greet
>    puts 'hi'
>  end
> end
>
> obj = MyClass.new
> obj.greet
>
> --output:--
> hi
>
>
> Now here is a more complex version:
>
> def create_class
>  cl = Class.new
>
>  cl.class_eval do
>    yield
>  end
>
>  return cl
> end
>
>
> MyClass = create_class do
>
>  def greet
>    puts 'hello'
>  end
>
> end
>
>
> obj = MyClass.new
> obj.send(:greet)
> #obj.greet   #private method -- NoMethodError
>
>
> Why is greet() a private method?
>
> --
> Posted via http://www.ruby-forum.com/.
>
>