Implement String#hex

This commit is contained in:
mattn
2014-03-27 11:28:29 +09:00
parent a4f4db975a
commit 0df65751c6
2 changed files with 17 additions and 0 deletions
+7
View File
@@ -163,6 +163,12 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self)
return mrb_false_value();
}
static mrb_value
mrb_str_hex(mrb_state *mrb, mrb_value self)
{
return mrb_str_to_inum(mrb, self, 16, FALSE);
}
void
mrb_mruby_string_ext_gem_init(mrb_state* mrb)
{
@@ -176,6 +182,7 @@ mrb_mruby_string_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, s, "<<", mrb_str_concat2, MRB_ARGS_REQ(1));
mrb_define_method(mrb, s, "start_with?", mrb_str_start_with, MRB_ARGS_REST());
mrb_define_method(mrb, s, "end_with?", mrb_str_end_with, MRB_ARGS_REST());
mrb_define_method(mrb, s, "hex", mrb_str_hex, MRB_ARGS_NONE());
}
void