Hi,

At Wed, 24 Oct 2001 09:26:47 +0900,
David Alan Black <dblack / candle.superlink.net> wrote:
> This emerged from some tinkering, and I actually thought it was kind
> of cool:
> 
>   class Module
>     def privately(&block)
>       instance_eval "private; block.call; public"
>     end
>   end

Once I'd suggested a simillar.  Attaching the patch.

class Foo
  private do
    def private_method
    end

    protected do
      def protected_method
      end
    end
  end

  def public_method
  end
end


Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.166 diff -u -2 -p -r1.166 eval.c --- eval.c 2001/03/16 08:30:09 1.166 +++ eval.c 2001/03/16 15:40:09 @@ -5422,4 +5422,23 @@ set_method_visibility(self, argc, argv, } +static void +change_scope(mod, vmode) + VALUE mod; + int vmode; +{ + int old_vmode = scope_vmode; + SCOPE_SET(vmode); + if (rb_block_given_p()) { + int state; + PUSH_TAG(PROT_NONE); + if ((state = EXEC_TAG()) == 0) { + rb_mod_module_eval(0, 0, mod); + } + POP_TAG(); + SCOPE_SET(old_vmode); + if (state) JUMP_TAG(state); + } +} + static VALUE rb_mod_public(argc, argv, module) @@ -5430,5 +5449,5 @@ rb_mod_public(argc, argv, module) secure_visibility(module); if (argc == 0) { - SCOPE_SET(SCOPE_PUBLIC); + change_scope(module, SCOPE_PUBLIC); } else { @@ -5446,5 +5465,5 @@ rb_mod_protected(argc, argv, module) secure_visibility(module); if (argc == 0) { - SCOPE_SET(SCOPE_PROTECTED); + change_scope(module, SCOPE_PROTECTED); } else { @@ -5462,5 +5481,5 @@ rb_mod_private(argc, argv, module) secure_visibility(module); if (argc == 0) { - SCOPE_SET(SCOPE_PRIVATE); + change_scope(module, SCOPE_PRIVATE); } else {
Nobu Nakada