Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 98f907d72ba0
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4c7a6957547a
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 22, 2014

  1. 1
    Copy the full SHA
    bbc69ad View commit details
  2. 2
    Copy the full SHA
    4c7a695 View commit details
Showing with 47 additions and 0 deletions.
  1. +47 −0 core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
47 changes: 47 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -1197,4 +1197,51 @@ public RubyString upcaseBang(RubyString string) {
}
}

@CoreMethod(names = "capitalize!")
public abstract static class CapitalizeBangNode extends CoreMethodNode {

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

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

@Specialization
public RubyString capitalizeBang(RubyString string) {
notDesignedForCompilation();
String javaString = string.toString();
String head = javaString.substring(0, 1).toUpperCase();
String tail = javaString.substring(1, javaString.length()).toLowerCase();

string.set(ByteList.create((head + tail)));
return string;
}
}

@CoreMethod(names = "capitalize")
public abstract static class CapitalizeNode extends CoreMethodNode {

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

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

@Specialization
public RubyString capitalize(RubyString string) {
notDesignedForCompilation();

String javaString = string.toString();
String head = javaString.substring(0, 1).toUpperCase();
String tail = javaString.substring(1, javaString.length()).toLowerCase();

return string.getContext().makeString(head + tail);
}

}

}