Skip to content

Commit

Permalink
[Truffle] Moving String#end_with? out to Rubinius.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 23, 2015
1 parent 505bdbc commit 53bc732
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/string/end_with_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1214,25 +1214,6 @@ public RubyEncoding encoding(RubyString string) {
}
}

@CoreMethod(names = "end_with?", required = 1)
public abstract static class EndWithNode extends CoreMethodNode {

public EndWithNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public EndWithNode(EndWithNode prev) {
super(prev);
}

@Specialization
public boolean endWith(RubyString string, RubyString b) {
notDesignedForCompilation();

return string.toString().endsWith(b.toString());
}
}

@CoreMethod(names = "force_encoding", required = 1)
public abstract static class ForceEncodingNode extends CoreMethodNode {

Expand Down
11 changes: 11 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,17 @@ def codepoints
end
end

def end_with?(*suffixes)
suffixes.each do |original_suffix|
suffix = Rubinius::Type.check_convert_type original_suffix, String, :to_str
unless suffix
raise TypeError, "no implicit conversion of #{original_suffix.class} into String"
end
return true if self[-suffix.length, suffix.length] == suffix
end
false
end

def to_sub_replacement(result, match)
index = 0
while index < @num_bytes
Expand Down

0 comments on commit 53bc732

Please sign in to comment.