Update range.h.md
authorRalph Desir <[email protected]>
Thu, 3 Sep 2015 18:52:21 +0000 (3 14:52 -0400)
committerRalph Desir <[email protected]>
Thu, 3 Sep 2015 18:52:21 +0000 (3 14:52 -0400)
doc/api/mruby/range.h.md

index e69de29..188e6ed 100644 (file)
@@ -0,0 +1,47 @@
+#### mrb_range_new\r
+```C\r
+  mrb_value mrb_range_new(mrb_state*, mrb_value, mrb_value, mrb_bool);\r
+```\r
+Initializes a Range. The first mrb_value being the beginning value and second being the ending value.\r
+The third parameter is an mrb_bool value that represents the inclusion or exclusion of the last value.\r
+If the third parameter is 0 then it includes the last value in the range. If the third parameter is 1 \r
+then it excludes the last value in the range.\r
+C code\r
+```C\r
+  #include <stdio.h>\r
+  #include <mruby.h>\r
+  #include "mruby/range.h" // Needs the range header.\r
+  #include "mruby/compile.h"\r
+\r
+  int main(int argc, char *argv[])\r
+    {\r
+      mrb_int beg = 0;\r
+      mrb_int end = 2;\r
+      mrb_bool exclude = 1;\r
+      mrb_value range_obj;\r
+      mrb_state *mrb = mrb_open();\r
+      if (!mrb) { /* handle error */ }\r
+      FILE *fp = fopen("test.rb","r");\r
+      range_obj = mrb_range_new(mrb, mrb_fixnum_value(beg), mrb_fixnum_value(end), exclude);\r
+      mrb_value obj = mrb_load_file(mrb,fp);\r
+      mrb_funcall(mrb, obj, "method_name", 1, range_obj);\r
+      fclose(fp);\r
+      mrb_close(mrb);\r
+      return 0;\r
+    }\r
+```\r
+Ruby code\r
+```Ruby\r
+  class Example_Class\r
+    def method_name(a)\r
+      puts a\r
+      puts a.class\r
+    end\r
+  end\r
+  Example_Class.new\r
+```\r
+This returns the following:\r
+```Ruby\r
+  0...2\r
+  Range\r
+```\r