Skip to content

Commit 53bc732

Browse files
committed
[Truffle] Moving String#end_with? out to Rubinius.
1 parent 505bdbc commit 53bc732

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

spec/truffle/tags/core/string/end_with_tags.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,25 +1214,6 @@ public RubyEncoding encoding(RubyString string) {
12141214
}
12151215
}
12161216

1217-
@CoreMethod(names = "end_with?", required = 1)
1218-
public abstract static class EndWithNode extends CoreMethodNode {
1219-
1220-
public EndWithNode(RubyContext context, SourceSection sourceSection) {
1221-
super(context, sourceSection);
1222-
}
1223-
1224-
public EndWithNode(EndWithNode prev) {
1225-
super(prev);
1226-
}
1227-
1228-
@Specialization
1229-
public boolean endWith(RubyString string, RubyString b) {
1230-
notDesignedForCompilation();
1231-
1232-
return string.toString().endsWith(b.toString());
1233-
}
1234-
}
1235-
12361217
@CoreMethod(names = "force_encoding", required = 1)
12371218
public abstract static class ForceEncodingNode extends CoreMethodNode {
12381219

truffle/src/main/ruby/core/rubinius/common/string.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,17 @@ def codepoints
527527
end
528528
end
529529

530+
def end_with?(*suffixes)
531+
suffixes.each do |original_suffix|
532+
suffix = Rubinius::Type.check_convert_type original_suffix, String, :to_str
533+
unless suffix
534+
raise TypeError, "no implicit conversion of #{original_suffix.class} into String"
535+
end
536+
return true if self[-suffix.length, suffix.length] == suffix
537+
end
538+
false
539+
end
540+
530541
def to_sub_replacement(result, match)
531542
index = 0
532543
while index < @num_bytes

0 commit comments

Comments
 (0)