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
2ff67f8d
Commit
2ff67f8d
authored
Oct 25, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2618 from suzukaze/add-kernel.Float
Add Kernel#Float
parents
d3c7e117
140e9bbf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
mrbgems/mruby-kernel-ext/src/kernel.c
mrbgems/mruby-kernel-ext/src/kernel.c
+22
-0
mrbgems/mruby-kernel-ext/test/kernel.rb
mrbgems/mruby-kernel-ext/test/kernel.rb
+7
-0
No files found.
mrbgems/mruby-kernel-ext/src/kernel.c
View file @
2ff67f8d
...
@@ -23,6 +23,27 @@ mrb_f_method(mrb_state *mrb, mrb_value self)
...
@@ -23,6 +23,27 @@ mrb_f_method(mrb_state *mrb, mrb_value self)
return
mrb_nil_value
();
return
mrb_nil_value
();
}
}
/*
* call-seq:
* Float(arg) -> float
*
* Returns <i>arg</i> converted to a float. Numeric types are converted
* directly, the rest are converted using <i>arg</i>.to_f.
*
* Float(1) #=> 1.0
* Float(123.456) #=> 123.456
* Float("123.456") #=> 123.456
* Float(nil) #=> TypeError
*/
static
mrb_value
mrb_f_float
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
arg
;
mrb_get_args
(
mrb
,
"o"
,
&
arg
);
return
mrb_Float
(
mrb
,
arg
);
}
/*
/*
* call-seq:
* call-seq:
* String(arg) -> string
* String(arg) -> string
...
@@ -116,6 +137,7 @@ mrb_mruby_kernel_ext_gem_init(mrb_state *mrb)
...
@@ -116,6 +137,7 @@ mrb_mruby_kernel_ext_gem_init(mrb_state *mrb)
mrb_define_module_function
(
mrb
,
krn
,
"fail"
,
mrb_f_raise
,
MRB_ARGS_OPT
(
2
));
mrb_define_module_function
(
mrb
,
krn
,
"fail"
,
mrb_f_raise
,
MRB_ARGS_OPT
(
2
));
mrb_define_method
(
mrb
,
krn
,
"__method__"
,
mrb_f_method
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
krn
,
"__method__"
,
mrb_f_method
,
MRB_ARGS_NONE
());
mrb_define_module_function
(
mrb
,
krn
,
"Float"
,
mrb_f_float
,
MRB_ARGS_REQ
(
1
));
mrb_define_module_function
(
mrb
,
krn
,
"String"
,
mrb_f_string
,
MRB_ARGS_REQ
(
1
));
mrb_define_module_function
(
mrb
,
krn
,
"String"
,
mrb_f_string
,
MRB_ARGS_REQ
(
1
));
mrb_define_module_function
(
mrb
,
krn
,
"Array"
,
mrb_f_array
,
MRB_ARGS_REQ
(
1
));
mrb_define_module_function
(
mrb
,
krn
,
"Array"
,
mrb_f_array
,
MRB_ARGS_REQ
(
1
));
mrb_define_module_function
(
mrb
,
krn
,
"Hash"
,
mrb_f_hash
,
MRB_ARGS_REQ
(
1
));
mrb_define_module_function
(
mrb
,
krn
,
"Hash"
,
mrb_f_hash
,
MRB_ARGS_REQ
(
1
));
...
...
mrbgems/mruby-kernel-ext/test/kernel.rb
View file @
2ff67f8d
...
@@ -17,6 +17,13 @@ assert('Kernel#__method__') do
...
@@ -17,6 +17,13 @@ assert('Kernel#__method__') do
assert_equal
(
:m2
,
c
.
new
.
m2
)
assert_equal
(
:m2
,
c
.
new
.
m2
)
end
end
assert
(
'Kernel#Float'
)
do
assert_equal
(
1.0
,
Float
(
1
))
assert_equal
(
123.456
,
Float
(
123.456
))
assert_equal
(
123.456
,
Float
(
"123.456"
))
assert_raise
(
TypeError
)
{
Float
(
nil
)
}
end
assert
(
'Kernel#String'
)
do
assert
(
'Kernel#String'
)
do
assert_equal
(
"main"
,
String
(
self
))
assert_equal
(
"main"
,
String
(
self
))
assert_equal
(
"Object"
,
String
(
self
.
class
))
assert_equal
(
"Object"
,
String
(
self
.
class
))
...
...
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