# \[Bug #3445\] 1.9.2-preview3 $B$G(B Object#extend $B$9$k$H(B public\_methods(false) $B$+$i%a%=%C

**URL:** <https://www.ruby-forum.com/t/bug-3445-1-9-2-preview3-b-g-b-object-extend-b-9-k-h-b-public-methods-false-b-i-a-c/190296>\
**Category:** Development\
**Created:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/bug-3445-1-9-2-preview3-b-g-b-object-extend-b-9-k-h-b-public-methods-false-b-i-a-c/190296 "2010-06-17T16:22:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f08c70/32.png) [@Yusuke\_E](https://www.ruby-forum.com/u/Yusuke_E)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/bug-3445-1-9-2-preview3-b-g-b-object-extend-b-9-k-h-b-public-methods-false-b-i-a-c/190296/1 "2010-06-17T16:22:42Z")

</div>

e$B%A%1%C%He(B #3445 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$BC4Ev\<Te(B Yusuke E.e$B$K%;%C%He(B

e$B1sF#$G$9!#e(B

e$B85!9$OFC0[%/%i%9$N%a%=%C%I$O0z?t$,e(B false  
e$B$G$bNs5s$5$l$F$$$?$N$G$9$,!"e(B  
#2993  
e$B$N$?$a$KFC0[%/%i%9$N%a%=%C%I$,Ns5s$5$l$J$/$J$C$?$3$H$,860x$G$9!#e(B

Module#public\_instance\_methods(false):  
e$BFC0[%/%i%9$N%a%=%C%I$rNs5s$7$J$$e(B  
Object#public\_methods(false): e$BFC0[%/%i%9$N%a%=%C%I$rNs5s$r$9$ke(B

e$B$H$9$k%Q%C%A$r=q$$$F$\_$^$7$?!#$d$d$3$7$$$G$9$M!#e(B

e$B%F%9%H$N%(%i!\<$OA}$($:!"$3$N%A%1%C%H$GJs9p$5$l$F$$$k%3!\<%I$O=\>MhDL$j$Ne(B  
e$B5sF0$K$J$j$^$9!#H?BP$,$J$1$l$P%3%\_%C%H$7$^$9!#e(B

diff --git a/class.c b/class.c  
index 9a3984a…b6f0999 100644  
— a/class.c  
+++ b/class.c  
@@ -833,7 +833,7 @@ method\_entry(ID key, const rb\_method\_entry\_t \*me,  
st\_table \*list)  
}

static VALUE  
-class\_instance\_method\_list(int argc, VALUE \*argv, VALUE mod, int  
(\*func) (ID, long, VALUE))  
+class\_instance\_method\_list(int argc, VALUE \*argv, VALUE mod, int obj,  
int (\*func) (ID, long, VALUE))  
{  
VALUE ary;  
int recur;  
@@ -852,6 +852,7 @@ class\_instance\_method\_list(int argc, VALUE \*argv,  
VALUE mod, int (\*func) (ID, lo  
for (; mod; mod = RCLASS\_SUPER(mod)) {  
st\_foreach(RCLASS\_M\_TBL(mod), method\_entry, (st\_data\_t)list);  
if (BUILTIN\_TYPE(mod) == T\_ICLASS) continue;

- if (obj && FL\_TEST(mod, FL\_SINGLETON)) continue;  
if (!recur) break;  
}  
ary = rb\_ary\_new();  
@@ -891,7 +892,7 @@ class\_instance\_method\_list(int argc, VALUE \*argv,  
VALUE mod, int (\*func) (ID, lo  
VALUE  
rb\_class\_instance\_methods(int argc, VALUE \*argv, VALUE mod)  
{

- return class\_instance\_method\_list(argc, argv, mod, ins\_methods\_i);

- return class\_instance\_method\_list(argc, argv, mod, 0,  
ins\_methods\_i);  
}

/\*  
@@ -906,7 +907,7 @@ rb\_class\_instance\_methods(int argc, VALUE \*argv,  
VALUE mod)  
VALUE  
rb\_class\_protected\_instance\_methods(int argc, VALUE \*argv, VALUE mod)  
{

- return class\_instance\_method\_list(argc, argv, mod,  
ins\_methods\_prot\_i);

- return class\_instance\_method\_list(argc, argv, mod, 0,  
ins\_methods\_prot\_i);  
}

/\*  
@@ -929,7 +930,7 @@ rb\_class\_protected\_instance\_methods(int argc, VALUE  
\*argv, VALUE mod)  
VALUE  
rb\_class\_private\_instance\_methods(int argc, VALUE \*argv, VALUE mod)  
{

- return class\_instance\_method\_list(argc, argv, mod,  
ins\_methods\_priv\_i);

- return class\_instance\_method\_list(argc, argv, mod, 0,  
ins\_methods\_priv\_i);  
}

/\*  
@@ -944,7 +945,93 @@ rb\_class\_private\_instance\_methods(int argc, VALUE  
\*argv, VALUE mod)  
VALUE  
rb\_class\_public\_instance\_methods(int argc, VALUE \*argv, VALUE mod)  
{

- return class\_instance\_method\_list(argc, argv, mod,  
ins\_methods\_pub\_i);

- return class\_instance\_method\_list(argc, argv, mod, 0,  
ins\_methods\_pub\_i);  
+}
- 

+/\*

- 
  - call-seq:

- 
  - 

```
obj.methods -> array

```

- 
  - 

- 
  - Returns a list of the names of methods publicly accessible in

- 
  - _obj_. This will include all the methods accessible in

- 
  - _obj_'s ancestors.

- 
  - 

- 
  - 

```
class Klass

```

- 
  - 

```
  def kMethod()

```

- 
  - 

```
  end

```

- 
  - 

```
end

```

- 
  - 

```
k = Klass.new

```

- 
  - 

```
k.methods[0..9] #=> [:kMethod, :freeze, :nil?, :is_a?,

```

- 
  - 

```
                   # :class, :instance_variable_set,

```

- 
  - 

```
                   # :methods, :extend, : __send__ , 

```

:instance\_eval]

- 
  - 

```
k.methods.length #=> 42

```

- \*/
- 

+VALUE  
+rb\_obj\_methods(int argc, VALUE \*argv, VALUE obj)  
+{

- retry:
- if (argc == 0) {
- VALUE args[1];
- 
- args[0] = Qtrue;
- return class\_instance\_method\_list(argc, argv, CLASS\_OF(obj), 1,  
ins\_methods\_i);
- }
- else {
- VALUE recur;
- 
- rb\_scan\_args(argc, argv, “1”, &recur);
- if (RTEST(recur)) {
- 

```
 argc = 0;

```

- 

```
 goto retry;

```

- }
- return rb\_obj\_singleton\_methods(argc, argv, obj);
- }  
+}
- 

+/\*

- 
  - call-seq:

- 
  - 

```
obj.protected_methods(all=true) -> array

```

- 
  - 

- 
  - Returns the list of protected methods accessible to _obj_. If

- 
  - the _all_ parameter is set to `false`, only those  
methods

- 
  - in the receiver will be listed.

- \*/
- 

+VALUE  
+rb\_obj\_protected\_methods(int argc, VALUE \*argv, VALUE obj)  
+{

- return class\_instance\_method\_list(argc, argv, CLASS\_OF(obj), 1,  
ins\_methods\_prot\_i);  
+}
- 

+/\*

- 
  - call-seq:

- 
  - 

```
obj.private_methods(all=true) -> array

```

- 
  - 

- 
  - Returns the list of private methods accessible to _obj_. If

- 
  - the _all_ parameter is set to `false`, only those  
methods

- 
  - in the receiver will be listed.

- \*/
- 

+VALUE  
+rb\_obj\_private\_methods(int argc, VALUE \*argv, VALUE obj)  
+{

- return class\_instance\_method\_list(argc, argv, CLASS\_OF(obj), 1,  
ins\_methods\_priv\_i);  
+}
- 

+/\*

- 
  - call-seq:

- 
  - 

```
obj.public_methods(all=true) -> array

```

- 
  - 

- 
  - Returns the list of public methods accessible to _obj_. If

- 
  - the _all_ parameter is set to `false`, only those  
methods

- 
  - in the receiver will be listed.

- \*/
- 

+VALUE  
+rb\_obj\_public\_methods(int argc, VALUE \*argv, VALUE obj)  
+{

- return class\_instance\_method\_list(argc, argv, CLASS\_OF(obj), 1,  
ins\_methods\_pub\_i);  
}

/\*  
diff --git a/object.c b/object.c  
index 414c3a9…f52522d 100644  
— a/object.c  
+++ b/object.c  
@@ -1751,109 +1751,10 @@ rb\_mod\_const\_defined(int argc, VALUE \*argv,  
VALUE mod)  
return RTEST(recur) ? rb\_const\_defined(mod, id) :  
rb\_const\_defined\_at(mod, id);  
}

-/\*

- 
  - call-seq:

- 
  - 

```
obj.methods -> array

```

- 
  - 

- 
  - Returns a list of the names of methods publicly accessible in

- 
  - _obj_. This will include all the methods accessible in

- 
  - _obj_'s ancestors.

- 
  - 

- 
  - 

```
class Klass

```

- 
  - 

```
  def kMethod()

```

- 
  - 

```
  end

```

- 
  - 

```
end

```

- 
  - 

```
k = Klass.new

```

- 
  - 

```
k.methods[0..9] #=> [:kMethod, :freeze, :nil?, :is_a?,

```

- 
  - 

```
                   # :class, :instance_variable_set,

```

- 
  - 

```
                   # :methods, :extend, : __send__ , 

```

:instance\_eval]

- 
  - 

```
k.methods.length #=> 42

```

- \*/
- 

-static VALUE  
-rb\_obj\_methods(int argc, VALUE \*argv, VALUE obj)  
-{

- retry:
- if (argc == 0) {
- VALUE args[1];
- 
- args[0] = Qtrue;
- return rb\_class\_instance\_methods(1, args, CLASS\_OF(obj));
- }
- else {
- VALUE recur;
- 
- rb\_scan\_args(argc, argv, “1”, &recur);
- if (RTEST(recur)) {
- 

```
 argc = 0;

```

- 

```
 goto retry;

```

- }
- return rb\_obj\_singleton\_methods(argc, argv, obj);
- }  
-}
- 

-/\*

- 
  - call-seq:

- 
  - 

```
obj.protected_methods(all=true) -> array

```

- 
  - 

- 
  - Returns the list of protected methods accessible to _obj_. If

- 
  - the _all_ parameter is set to `false`, only those  
methods

- 
  - in the receiver will be listed.

- \*/
- 

-static VALUE  
-rb\_obj\_protected\_methods(int argc, VALUE \*argv, VALUE obj)  
-{

- if (argc == 0) { /\* hack to stop warning \*/
- VALUE args[1];
- 
- args[0] = Qtrue;
- return rb\_class\_protected\_instance\_methods(1, args, CLASS\_OF(obj));
- }
- return rb\_class\_protected\_instance\_methods(argc, argv,  
CLASS\_OF(obj));  
-}
- 

-/\*

- 
  - call-seq:

- 
  - 

```
obj.private_methods(all=true) -> array

```

- 
  - 

- 
  - Returns the list of private methods accessible to _obj_. If

- 
  - the _all_ parameter is set to `false`, only those  
methods

- 
  - in the receiver will be listed.

- \*/
- 

-static VALUE  
-rb\_obj\_private\_methods(int argc, VALUE \*argv, VALUE obj)  
-{

- if (argc == 0) { /\* hack to stop warning \*/
- VALUE args[1];
- 
- args[0] = Qtrue;
- return rb\_class\_private\_instance\_methods(1, args, CLASS\_OF(obj));
- }
- return rb\_class\_private\_instance\_methods(argc, argv,  
CLASS\_OF(obj));  
-}
- 

-/\*

- 
  - call-seq:

- 
  - 

```
obj.public_methods(all=true) -> array

```

- 
  - 

- 
  - Returns the list of public methods accessible to _obj_. If

- 
  - the _all_ parameter is set to `false`, only those  
methods

- 
  - in the receiver will be listed.

- \*/
- 

-static VALUE  
-rb\_obj\_public\_methods(int argc, VALUE \*argv, VALUE obj)  
-{

- if (argc == 0) { /\* hack to stop warning \*/
- VALUE args[1];
- 
- args[0] = Qtrue;
- return rb\_class\_public\_instance\_methods(1, args, CLASS\_OF(obj));
- }
- return rb\_class\_public\_instance\_methods(argc, argv, CLASS\_OF(obj));  
-}  
+VALUE rb\_obj\_methods(int argc, VALUE \*argv, VALUE obj);  
+VALUE rb\_obj\_protected\_methods(int argc, VALUE \*argv, VALUE obj);  
+VALUE rb\_obj\_private\_methods(int argc, VALUE \*argv, VALUE obj);  
+VALUE rb\_obj\_public\_methods(int argc, VALUE \*argv, VALUE obj);

/\*

- call-seq:

## – Yusuke E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[http://redmine.ruby-lang.org/issues/show/3445](http://redmine.ruby-lang.org/issues/show/3445)
