Is it possible to convert this Java code to JRuby?
Files.walkFileTree(path, new SimpleFileVisitor() {
@Override
public FileVisitResult preVisitDirectory(Path path) {
return FileVisitResult.CONTINUE;
}
});
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
On Thu, May 20, 2010 at 5:42 PM, consiliens [email protected]
wrote:
Is it possible to convert this Java code to JRuby?
Files.walkFileTree(path, new SimpleFileVisitor() {
@Override
public FileVisitResult preVisitDirectory(Path path) {
return FileVisitResult.CONTINUE;
}
});
Generics are erased at runtime, so it should be straightforward:
Files.walkFileTree(path, Class.new(SimpleFileVisitor) do
def preVisitDirectory(path)
FileVisitResult::CONTINUE
end
end.new)
Though to extend a Java class in Ruby it would be more efficient and
probably more conventional to declare a class once rather than inline
every time the walkFileTree method is called.
class MyVisitor < SimpleFileVisitor
def preVisitDirectory(path)
FileVisitResult::CONTINUE
end
end
Files.walkFileTree(path, MyVisitor.new)
/Nick
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Do you want to call this code from ruby using the Java integration
features
of JRuby? Or do you want to convert this to idiomatic ruby?
Joe
I wanted to convert the code to idiomatic ruby, which Nick kindly
illustrated.
On 05/21/2010 07:23 AM, Joseph A. wrote:
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
On 05/21/2010 07:19 AM, Nick S. wrote:
every time the walkFileTree method is called.
Thank you.
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email