ruby中有类似perlform的东西吗?

ruby中有类似perlform的东西吗?,ruby,Ruby,使用,我可以如下格式化控制台输出: #Print report $~ = 'REPORT'; $^ = 'REPORT_TOP'; write ; # Specify format format REPORT_TOP = Charge Code Hours Description ============= ======== =============================================== . format REPORT = @<<

使用,我可以如下格式化控制台输出:

#Print report    
$~ = 'REPORT';
$^ = 'REPORT_TOP';
write ;

# Specify format
format REPORT_TOP =
Charge Code   Hours    Description
============= ======== ===============================================
.

format REPORT =
@<<<<<<<<<<<< @<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$reportChargeCode, $reportHours, $reportDescription
.
您可以使用gem:

需要“格式化程序”
包括格式化程序
#指定格式

report\u top=不清楚(对我来说)上面的代码实现了什么。你能解释一下期望的行为和输出吗?我想Formator会帮我完成这项工作,谢谢!
Charge Code   Hours    Description
============= ======== ===============================================
CS5510        2.2575   hw13
ECE3710       5.678333 duck hunt game
require "formatr"
include FormatR

# Specify format
report_top = <<DOT
Charge Code   Hours    Description
============= ======== ===============================================
DOT

report = <<DOT
@<<<<<<<<<<<< @<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
reportChargeCode, reportHours, reportDescription
DOT

body_fmt = Format.new (report_top, report)

body_fmt.setPageLength(10)
num = 1

Reaports.each do |(reportChargeCode, reportHours, reportDescription)|
    body_fmt.printFormat(binding)
end