Project

General

Profile

Feature #11689 ยป 0001-Add-Method-visibility-and-UnboundMethod-visibility.patch

yui-knk (Kaneko Yuichiro), 11/15/2015 04:53 AM

View differences:

proc.c
2558 2558
}
2559 2559

  
2560 2560
/*
2561
 *  call-seq:
2562
 *    meth.visibility    -> symbol
2563
 *
2564
 *  Returns a symbol (:public, :private, or :protected).
2565
 */
2566

  
2567
static VALUE
2568
rb_method_visibility(VALUE method)
2569
{
2570
    const struct METHOD *data;
2571
    VALUE sym;
2572

  
2573
    TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
2574
    switch(METHOD_ENTRY_VISI(data->me)) {
2575
      case METHOD_VISI_UNDEF:
2576
      case METHOD_VISI_PUBLIC:    sym = ID2SYM(rb_intern("public")); break;
2577
      case METHOD_VISI_PRIVATE:   sym = ID2SYM(rb_intern("private")); break;
2578
      case METHOD_VISI_PROTECTED: sym = ID2SYM(rb_intern("protected")); break;
2579
      default: UNREACHABLE;
2580
    }
2581
    return sym;
2582
}
2583

  
2584
/*
2561 2585
 * call-seq:
2562 2586
 *   local_jump_error.exit_value  -> obj
2563 2587
 *
......
2929 2953
    rb_define_method(rb_cMethod, "source_location", rb_method_location, 0);
2930 2954
    rb_define_method(rb_cMethod, "parameters", rb_method_parameters, 0);
2931 2955
    rb_define_method(rb_cMethod, "super_method", method_super_method, 0);
2956
    rb_define_method(rb_cMethod, "visibility", rb_method_visibility, 0);
2932 2957
    rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
2933 2958
    rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
2934 2959
    rb_define_method(rb_mKernel, "singleton_method", rb_obj_singleton_method, 1);
......
2951 2976
    rb_define_method(rb_cUnboundMethod, "source_location", rb_method_location, 0);
2952 2977
    rb_define_method(rb_cUnboundMethod, "parameters", rb_method_parameters, 0);
2953 2978
    rb_define_method(rb_cUnboundMethod, "super_method", method_super_method, 0);
2979
    rb_define_method(rb_cUnboundMethod, "visibility", rb_method_visibility, 0);
2954 2980

  
2955 2981
    /* Module#*_method */
2956 2982
    rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
test/ruby/test_method.rb
888 888
    assert_nil(m, Feature9781)
889 889
  end
890 890

  
891
  def test_visibility_method
892
    v = Visibility.new
893
    assert_equal(:public, v.method(:mv1).visibility)
894
    assert_equal(:private, v.method(:mv2).visibility)
895
    assert_equal(:protected, v.method(:mv3).visibility)
896
  end
897

  
898
  def test_visibility_method_unbound
899
    assert_equal(:public, Visibility.instance_method(:mv1).visibility)
900
    assert_equal(:private, Visibility.instance_method(:mv2).visibility)
901
    assert_equal(:protected, Visibility.instance_method(:mv3).visibility)
902
  end
903

  
891 904
  def rest_parameter(*rest)
892 905
    rest
893 906
  end
894
-