Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
743432d4
Commit
743432d4
authored
Sep 03, 2015
by
Ralph Desir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update range.h.md
parent
8a09515c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
doc/api/mruby/range.h.md
doc/api/mruby/range.h.md
+47
-0
No files found.
doc/api/mruby/range.h.md
View file @
743432d4
#### 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
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment