Skip to content

Commit

Permalink
String#include? does not take integers
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Nov 17, 2016
1 parent 92be276 commit 57900d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
18 changes: 4 additions & 14 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,22 +1530,12 @@ mrb_str_hash_m(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_str_include(mrb_state *mrb, mrb_value self)
{
mrb_int i;
mrb_value str2;
mrb_bool include_p;

mrb_get_args(mrb, "o", &str2);
if (mrb_fixnum_p(str2)) {
include_p = (memchr(RSTRING_PTR(self), mrb_fixnum(str2), RSTRING_LEN(self)) != NULL);
}
else {
str2 = mrb_str_to_str(mrb, str2);
i = str_index(mrb, self, str2, 0);

include_p = (i != -1);
}

return mrb_bool_value(include_p);
mrb_get_args(mrb, "S", &str2);
if (str_index(mrb, self, str2, 0) < 0)
return mrb_bool_value(FALSE);
return mrb_bool_value(TRUE);
}

/* 15.2.10.5.22 */
Expand Down
2 changes: 0 additions & 2 deletions test/t/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@
end

assert('String#include?', '15.2.10.5.21') do
assert_true 'abc'.include?(97)
assert_false 'abc'.include?(100)
assert_true 'abc'.include?('a')
assert_false 'abc'.include?('d')
end
Expand Down

0 comments on commit 57900d8

Please sign in to comment.