diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-11-13 16:11:24 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-11-13 16:17:44 +0900 |
| commit | 01dddaf38525b631c61886758628afe8f04b6356 (patch) | |
| tree | 11ed60d7078d00e68dc8dface9dcbbabc056299e /mrbgems/mruby-class-ext | |
| parent | 451985d44be9078660bcb43e4c7d91b3398230a4 (diff) | |
| download | mruby-01dddaf38525b631c61886758628afe8f04b6356.tar.gz mruby-01dddaf38525b631c61886758628afe8f04b6356.zip | |
rename mruby-module-ext to mruby-class-ext; ref #2470
Diffstat (limited to 'mrbgems/mruby-class-ext')
| -rw-r--r-- | mrbgems/mruby-class-ext/mrbgem.rake | 5 | ||||
| -rw-r--r-- | mrbgems/mruby-class-ext/src/class.c | 23 | ||||
| -rw-r--r-- | mrbgems/mruby-class-ext/test/module.rb | 10 |
3 files changed, 38 insertions, 0 deletions
diff --git a/mrbgems/mruby-class-ext/mrbgem.rake b/mrbgems/mruby-class-ext/mrbgem.rake new file mode 100644 index 000000000..a384b1eef --- /dev/null +++ b/mrbgems/mruby-class-ext/mrbgem.rake @@ -0,0 +1,5 @@ +MRuby::Gem::Specification.new('mruby-class-ext') do |spec| + spec.license = 'MIT' + spec.author = 'mruby developers' + spec.summary = 'class/module extension' +end diff --git a/mrbgems/mruby-class-ext/src/class.c b/mrbgems/mruby-class-ext/src/class.c new file mode 100644 index 000000000..8ca7d66c2 --- /dev/null +++ b/mrbgems/mruby-class-ext/src/class.c @@ -0,0 +1,23 @@ +#include "mruby.h" +#include "mruby/class.h" +#include "mruby/string.h" + +static mrb_value +mrb_mod_name(mrb_state *mrb, mrb_value self) +{ + mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self)); + return mrb_nil_p(name)? name : mrb_str_dup(mrb, name); +} + +void +mrb_mruby_class_ext_gem_init(mrb_state *mrb) +{ + struct RClass *mod = mrb->module_class; + + mrb_define_method(mrb, mod, "name", mrb_mod_name, MRB_ARGS_NONE()); +} + +void +mrb_mruby_class_ext_gem_final(mrb_state *mrb) +{ +} diff --git a/mrbgems/mruby-class-ext/test/module.rb b/mrbgems/mruby-class-ext/test/module.rb new file mode 100644 index 000000000..f721ad0c6 --- /dev/null +++ b/mrbgems/mruby-class-ext/test/module.rb @@ -0,0 +1,10 @@ +assert 'Module#name' do + module A + class B + end + end + + assert_nil A::B.singleton_class.name + assert_equal 'Fixnum', Fixnum.name + assert_equal 'A::B', A::B.name +end |
