mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
variable.c: real class name
* variable.c (rb_class2name): should return real class name, not singleton class or iclass. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ddbee25a3b
commit
347e748bdd
6 changed files with 56 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Oct 20 05:24:29 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* variable.c (rb_class2name): should return real class name, not
|
||||
singleton class or iclass.
|
||||
|
||||
Sun Oct 20 04:18:48 2013 Aman Gupta <ruby@tmm1.net>
|
||||
|
||||
* variable.c (rb_class2name): call rb_tmp_class_path() directly to
|
||||
|
|
14
ext/-test-/class/class2name.c
Normal file
14
ext/-test-/class/class2name.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <ruby/ruby.h>
|
||||
|
||||
static VALUE
|
||||
class2name(VALUE self, VALUE klass)
|
||||
{
|
||||
const char *name = rb_class2name(klass);
|
||||
return name ? rb_str_new_cstr(name) : Qnil;
|
||||
}
|
||||
|
||||
void
|
||||
Init_class2name(VALUE klass)
|
||||
{
|
||||
rb_define_singleton_method(klass, "class2name", class2name, 1);
|
||||
}
|
7
ext/-test-/class/extconf.rb
Normal file
7
ext/-test-/class/extconf.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
|
||||
$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
|
||||
inits = $srcs.map {|s| File.basename(s, ".*")}
|
||||
inits.delete("init")
|
||||
inits.map! {|s|"X(#{s})"}
|
||||
$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
|
||||
create_makefile("-test-/class")
|
11
ext/-test-/class/init.c
Normal file
11
ext/-test-/class/init.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "ruby.h"
|
||||
|
||||
#define init(n) {void Init_##n(VALUE mod); Init_##n(mod);}
|
||||
|
||||
void
|
||||
Init_class(void)
|
||||
{
|
||||
VALUE mBug = rb_define_module("Bug");
|
||||
VALUE mod = rb_define_module_under(mBug, "Class");
|
||||
TEST_INIT_FUNCS(init);
|
||||
}
|
18
test/-ext-/class/test_class2name.rb
Normal file
18
test/-ext-/class/test_class2name.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'test/unit'
|
||||
require "-test-/class"
|
||||
|
||||
class Test_Class < Test::Unit::TestCase
|
||||
class Test_Class2Name < superclass
|
||||
def test_toplevel_class
|
||||
assert_equal("Object", Bug::Class.class2name(::Object))
|
||||
end
|
||||
|
||||
def test_toplevel_module
|
||||
assert_equal("Kernel", Bug::Class.class2name(::Kernel))
|
||||
end
|
||||
|
||||
def test_singleton_class
|
||||
assert_equal("Object", Bug::Class.class2name(::Object.new.singleton_class))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -386,7 +386,7 @@ const char *
|
|||
rb_class2name(VALUE klass)
|
||||
{
|
||||
int permanent;
|
||||
VALUE path = rb_tmp_class_path(klass, &permanent, rb_ivar_set);
|
||||
VALUE path = rb_tmp_class_path(rb_class_real(klass), &permanent, rb_ivar_set);
|
||||
if (NIL_P(path)) return NULL;
|
||||
return RSTRING_PTR(path);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue