Skip to content

Commit

Permalink
Showing 2 changed files with 40 additions and 12 deletions.
44 changes: 32 additions & 12 deletions core/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Original file line number Diff line number Diff line change
@@ -175,42 +175,42 @@ public RubyNilClass eachLine(VirtualFrame frame, RubyFile file, RubyProc block)

}

@CoreMethod(names = {"exist?", "exists?"}, onSingleton = true, required = 1)
public abstract static class ExistsNode extends CoreMethodNode {
@CoreMethod(names = "executable?", onSingleton = true, required = 1)
public abstract static class ExecutableNode extends CoreMethodNode {

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

public ExistsNode(ExistsNode prev) {
public ExecutableNode(ExecutableNode prev) {
super(prev);
}

@Specialization
public boolean exists(RubyString path) {
public boolean executable(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).isFile();
return new File(path.toString()).canExecute();
}

}

@CoreMethod(names = "executable?", onSingleton = true, required = 1)
public abstract static class ExecutableNode extends CoreMethodNode {
@CoreMethod(names = {"exist?", "exists?"}, onSingleton = true, required = 1)
public abstract static class ExistsNode extends CoreMethodNode {

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

public ExecutableNode(ExecutableNode prev) {
public ExistsNode(ExistsNode prev) {
super(prev);
}

@Specialization
public boolean executable(RubyString path) {
public boolean exists(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).canExecute();
return new File(path.toString()).exists();
}

}
@@ -298,6 +298,26 @@ public static void join(StringBuilder builder, Object[] parts) {
}
}

@CoreMethod(names = "path", onSingleton = true, required = 1)
public abstract static class PathNode extends CoreMethodNode {

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

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

@Specialization
public RubyString path(RubyString path) {
notDesignedForCompilation();

return getContext().makeString(path.toString());
}

}

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

Original file line number Diff line number Diff line change
@@ -98,6 +98,14 @@ public static RubyFile open(RubyContext context, String fileName, String mode) {
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else if (mode.equals("a") || mode.equals("ab")) {
reader = null;

try {
writer = new OutputStreamWriter(new FileOutputStream(fileName, true));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else {
throw new UnsupportedOperationException();
}

0 comments on commit a15f7c2

Please sign in to comment.