From a5b416e2ce31f28ec4c588b3bc1d0b0567faf7ba Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Wed, 14 Oct 2015 02:50:12 -0400 Subject: Added documentation for mrb_undef_method --- build_config.rb | 6 +++--- include/mruby.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/build_config.rb b/build_config.rb index 96b1d4684..427600a23 100644 --- a/build_config.rb +++ b/build_config.rb @@ -21,7 +21,7 @@ MRuby::Build.new do |conf| # include the default GEMs conf.gembox 'default' - + conf.gem '/home/thamav/tests/mrbgems_test' # C compiler settings # conf.cc do |cc| # cc.command = ENV['CC'] || 'gcc' @@ -82,7 +82,7 @@ MRuby::Build.new do |conf| # bintest # conf.enable_bintest end - +=begin MRuby::Build.new('host-debug') do |conf| # load specific toolchain settings @@ -117,7 +117,7 @@ MRuby::Build.new('test') do |conf| conf.gembox 'default' end - +=end # Define cross build settings # MRuby::CrossBuild.new('32bit') do |conf| # toolchain :gcc diff --git a/include/mruby.h b/include/mruby.h index fd64a07ec..2288f9546 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -243,8 +243,8 @@ MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value); * Include a module in another class or module. * Equivalent to: * - * module B * - * include A * + * module B + * include A * end * @param mrb_state* The current mruby state. * @param RClass* A reference to module or a class. @@ -348,6 +348,65 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, * @param mrb_value The value for the constant. */ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value); + +/** + * Undefines a method. + * + * # Ruby style + * + * class A + * + * def a + * "a" + * end + * + * end + * + * A.new.a # => a + * + * class B < A + * + * undef_method :a + * + * end + * + * B.new.a # => undefined method 'a' for B (NoMethodError) + * + * // C style + * + * mrb_value + * mrb_a(mrb_state *mrb){ + * + * return mrb_str_new_cstr(mrb, "a"); + * + * } + * + * void + * mrb_example_gem_init(mrb_state* mrb){ + * struct RClass *a; + * struct RClass *b; + * struct RClass *c; + * + * a = mrb_define_class(mrb, "A", mrb->object_class); + * + * mrb_define_method(mrb, a, "a", mrb_a, MRB_ARGS_NONE()); + * + * b = mrb_define_class(mrb, "B", a); + * + * c = mrb_define_class(mrb, "C", b); + * + * mrb_undef_method(mrb, c, "a"); + * + * } + * + * mrb_example_gem_final(mrb_state* mrb){ + * + * } + * + * @param mrb_state* The MRuby state reference. + * @param RClass* A class the method will be undefined from. + * @param constchar* The name of the method to be undefined. + */ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*); MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*); -- cgit v1.2.3 From d702b7fdf033e6c0d1cd2a18dc503b764d6da743 Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Wed, 14 Oct 2015 16:49:10 -0400 Subject: Add more YARD docs for mruby.h for mrb_undef_method and mrb_undef_class_method. --- include/mruby.h | 137 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 110 insertions(+), 27 deletions(-) diff --git a/include/mruby.h b/include/mruby.h index 2288f9546..cecf6fa47 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -292,17 +292,25 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n * Defines a class method. * # Ruby style * class Foo + * * def Foo.bar * end + * * end * // C style * mrb_value bar_method(mrb_state* mrb, mrb_value self){ + * * return mrb_nil_value(); + * * } * void mrb_example_gem_init(mrb_state* mrb){ + * * struct RClass *foo; + * * foo = mrb_define_class(mrb, "Foo", mrb->object_class); - * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); + * + * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); + * * } * @param mrb_state* The MRuby state reference. * @param RClass* The class where the class method will be defined. @@ -316,17 +324,24 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char /** * Defines a module fuction. * # Ruby style - * module Foo + * module Foo + * * def Foo.bar * end + * * end * // C style - * mrb_value bar_method(mrb_state* mrb, mrb_value self){ - * return mrb_nil_value(); + * mrb_value bar_method(mrb_state* mrb, mrb_value self){ + * + * return mrb_nil_value(); * * } - * void mrb_example_gem_init(mrb_state* mrb){ - * struct RClass *foo; - * foo = mrb_define_module(mrb, "Foo"); + * void mrb_example_gem_init(mrb_state* mrb){ + * + * struct RClass *foo; + * + * foo = mrb_define_module(mrb, "Foo"); + * * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); + * * } * @param mrb_state* The MRuby state reference. * @param RClass* The module where the module function will be defined. @@ -339,9 +354,28 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, /** * Defines a constant. * # Ruby style + * + * class ExampleClass + * * AGE = 22 + * + * end + * * // C style - * mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22)); + * #include + * #include + * + * void + * mrb_example_gem_init(mrb_state* mrb){ + * + * mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22)); + * + * } + * + * mrb_value + * mrb_example_gem_final(mrb_state* mrb){ + * + * } * @param mrb_state* The MRuby state reference. * @param RClass* A class or module the constant is defined in. * @param name The name of the constant. @@ -354,48 +388,50 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_ * * # Ruby style * - * class A + * class ExampleClassA * - * def a - * "a" + * def example_method + * "example" * end * * end * - * A.new.a # => a + * ExampleClassA.new.example_method # => example * - * class B < A + * class ExampleClassB < ExampleClassA * - * undef_method :a + * undef_method :example_method * * end * - * B.new.a # => undefined method 'a' for B (NoMethodError) + * ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError) * * // C style - * + * #include + * #include + * * mrb_value - * mrb_a(mrb_state *mrb){ + * mrb_example_method(mrb_state *mrb){ * - * return mrb_str_new_cstr(mrb, "a"); + * return mrb_str_new_cstr(mrb, "example"); * * } * * void * mrb_example_gem_init(mrb_state* mrb){ - * struct RClass *a; - * struct RClass *b; - * struct RClass *c; + * struct RClass *example_class_a; + * struct RClass *example_class_b; + * struct RClass *example_class_c; * - * a = mrb_define_class(mrb, "A", mrb->object_class); + * example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class); * - * mrb_define_method(mrb, a, "a", mrb_a, MRB_ARGS_NONE()); + * mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE()); * - * b = mrb_define_class(mrb, "B", a); + * example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a); * - * c = mrb_define_class(mrb, "C", b); + * example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b); * - * mrb_undef_method(mrb, c, "a"); + * mrb_undef_method(mrb, example_class_c, "example_method"); * * } * @@ -403,11 +439,58 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_ * * } * - * @param mrb_state* The MRuby state reference. + * @param mrb_state* The mruby state reference. * @param RClass* A class the method will be undefined from. * @param constchar* The name of the method to be undefined. */ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*); + +/** + * Undefine a class method. + * # Ruby style + * + * class ExampleClass + * + * def self.example_method + * "example" + * end + * + * end + * + * ExampleClass.example_method + * + * // C style + * #include + * #include + * + * mrb_value + * mrb_example_method(mrb_state *mrb){ + * + * return mrb_str_new_cstr(mrb, "example"); + * + * } + * + * void + * mrb_example_gem_init(mrb_state* mrb){ + * + * struct RClass *example_class; + * + * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); + * + * mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE()); + * + * mrb_undef_class_method(mrb, example_class, "example_method"); + * + * } + * + * void + * mrb_example_gem_final(mrb_state* mrb){ + * + * } + * @param mrb_state* The mruby state reference. + * @param RClass* A class the class method will be undefined from. + * @param constchar* The name of the class method to be undefined. + */ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*); /** -- cgit v1.2.3 From 2df9786f33e8be5ef50e36330e54e6d6d02bf234 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Wed, 14 Oct 2015 22:48:49 -0400 Subject: got rid of dummy gem i was testing --- build_config.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_config.rb b/build_config.rb index 427600a23..96b1d4684 100644 --- a/build_config.rb +++ b/build_config.rb @@ -21,7 +21,7 @@ MRuby::Build.new do |conf| # include the default GEMs conf.gembox 'default' - conf.gem '/home/thamav/tests/mrbgems_test' + # C compiler settings # conf.cc do |cc| # cc.command = ENV['CC'] || 'gcc' @@ -82,7 +82,7 @@ MRuby::Build.new do |conf| # bintest # conf.enable_bintest end -=begin + MRuby::Build.new('host-debug') do |conf| # load specific toolchain settings @@ -117,7 +117,7 @@ MRuby::Build.new('test') do |conf| conf.gembox 'default' end -=end + # Define cross build settings # MRuby::CrossBuild.new('32bit') do |conf| # toolchain :gcc -- cgit v1.2.3