summaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorRalph Desir <[email protected]>2015-09-03 14:52:21 -0400
committerRalph Desir <[email protected]>2015-09-03 14:52:21 -0400
commit743432d4ecc2052f6808d1e1012eb356e85ccb1e (patch)
tree43afab5cf066afef4bf922e7cf0a30908eab579e /doc
parent8a09515c6c7b1e8315c6b1accb92cb93d8e8138c (diff)
downloadmruby-743432d4ecc2052f6808d1e1012eb356e85ccb1e.tar.gz
mruby-743432d4ecc2052f6808d1e1012eb356e85ccb1e.zip
Update range.h.md
Diffstat (limited to 'doc')
-rw-r--r--doc/api/mruby/range.h.md47
1 files changed, 47 insertions, 0 deletions
diff --git a/doc/api/mruby/range.h.md b/doc/api/mruby/range.h.md
index e69de29bb..188e6ede6 100644
--- a/doc/api/mruby/range.h.md
+++ b/doc/api/mruby/range.h.md
@@ -0,0 +1,47 @@
+#### mrb_range_new
+```C
+ mrb_value mrb_range_new(mrb_state*, mrb_value, mrb_value, mrb_bool);
+```
+Initializes a Range. The first mrb_value being the beginning value and second being the ending value.
+The third parameter is an mrb_bool value that represents the inclusion or exclusion of the last value.
+If the third parameter is 0 then it includes the last value in the range. If the third parameter is 1
+then it excludes the last value in the range.
+C code
+```C
+ #include <stdio.h>
+ #include <mruby.h>
+ #include "mruby/range.h" // Needs the range header.
+ #include "mruby/compile.h"
+
+ int main(int argc, char *argv[])
+ {
+ mrb_int beg = 0;
+ mrb_int end = 2;
+ mrb_bool exclude = 1;
+ mrb_value range_obj;
+ mrb_state *mrb = mrb_open();
+ if (!mrb) { /* handle error */ }
+ FILE *fp = fopen("test.rb","r");
+ range_obj = mrb_range_new(mrb, mrb_fixnum_value(beg), mrb_fixnum_value(end), exclude);
+ mrb_value obj = mrb_load_file(mrb,fp);
+ mrb_funcall(mrb, obj, "method_name", 1, range_obj);
+ fclose(fp);
+ mrb_close(mrb);
+ return 0;
+ }
+```
+Ruby code
+```Ruby
+ class Example_Class
+ def method_name(a)
+ puts a
+ puts a.class
+ end
+ end
+ Example_Class.new
+```
+This returns the following:
+```Ruby
+ 0...2
+ Range
+```