我是Ruby的新手(作为Java开发人员),并试图实现一个方法(哦,抱歉,一个函数),它将以递归方式检索和生成子目录中的所有文件.
我把它实现为:
def file_list_recurse(dir)
Dir.foreach(dir) do |f|
next if f == '.' or f == '..'
f = dir + '/' + f
if File.directory? f
file_list_recurse(File.absolute_path f) { |x| yield x }
else
file = File.new(f)
yield file
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的问题是:
谢谢
PS:我的方法的示例用法是这样的:
curr_file = nil
file_list_recurse('.') do |file|
curr_file = file if curr_file == nil or curr_file.ctime > file.ctime
end
puts curr_file.to_path + ' ' + curr_file.ctime.to_s
Run Code Online (Sandbox Code Playgroud)
(那会从树中获取最旧的文件) …
是否有可能参考Kotlin中的通用函数?
例如,假设我有一个函数:
fun inline <reified T> appendToString(a: T, b: T) = a.toString() + b.toString
Run Code Online (Sandbox Code Playgroud)
你怎么能参考这个功能?这不会编译
var a = ::appendToString<Int>
Run Code Online (Sandbox Code Playgroud)