Skip to content
Permalink
Browse files
[Truffle] - Implements String#chr
  • Loading branch information
lucasallan committed Dec 22, 2014
1 parent dbff750 commit c1f0e4ca5d4427987f68ea5a72de40fc28d2ede6
Showing with 26 additions and 1 deletion.
  1. +26 −1 core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
@@ -1249,7 +1249,6 @@ public RubyString capitalize(RubyString string) {

}


@CoreMethod(names = "clear")
public abstract static class ClearNode extends CoreMethodNode {

@@ -1272,4 +1271,30 @@ public RubyString clear(RubyString string) {
}
}

@CoreMethod(names = "chr")
public abstract static class ChrNode extends CoreMethodNode {

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

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

@Specialization
public RubyString chr(RubyString string) {
notDesignedForCompilation();
if (string.toString().isEmpty()) {
return string;
} else {
String head = string.toString().substring(0, 1);
ByteList byteString = ByteList.create(head);
byteString.setEncoding(string.getBytes().getEncoding());

return string.getContext().makeString(byteString);
}
}
}

}

0 comments on commit c1f0e4c

Please sign in to comment.