如pp文档所述,如何让 pp 将行长换行(限制)为 79 个字符?
以下示例演示了 pp 不将输出限制为默认长度 79,如pp文档中所述。
- (1) 将以下代码放入文件(pprfile.rb)。
#!/usr/bin/env ruby require 'pp' STDIN.read.split("\n").each do |l| PP.pp(l) end
- (2) 将 Github 错字代码repo 和 cd 克隆到 repo 目录中。
- (3) 运行以下命令行:
- pprfile.rb < ./app/controllers/accounts_controller.rb | awk '长度($0) > 79 { 打印长度($0), $0 }'
- (4) 我希望所有的输出行都限制在小于或等于 79 个字符,但这是 II 得到的输出:
89 " redirect_back_or_default :controller => \"admin/dashboard\", :action => \"index\"" 94 " self.current_user = User.authenticate(params[:user][:login], params[:user][:password])" 82 " self.current_user.remember_me unless self.current_user.remember_token?" 82 " add_to_cookies(:typo_user_profile, self.current_user.profile_label, '/')" 91 " redirect_back_or_default :controller => \"admin/dashboard\", :action => \"index\"" 80 " @page_title = \"#{this_blog.blog_name} - #{_('Recover your password')}\"" 124 " @user = User.find(:first, :conditions => [\"login = ? or email = ?\", params[:user][:login], params[:user][:login]])" 108 " flash[:notice] = _(\"An email has been successfully sent to your address with your new password\")" 88 " redirect_to(:controller => \"accounts\", :action => \"signup\") if User.count == 0" 92 " redirect_to :controller => \"setup\", :action => \"index\" if ! this_blog.configured?"</li>