2012-03-23 89 views

回答

5

这些PARAMS属于class_eval方法,不以here document。通常的做法是,确保可以提高撤销代码的错误将以当前文件和正确的行号显示。

+0

我的意思是params对字符串块声明的影响,而不是class_eval方法 – daniloisr 2012-03-23 14:10:26

+0

@daniloisr我已经更新了答案。 – 2012-03-23 14:18:56

+0

不错,我无法想象。非常感谢你=) – daniloisr 2012-03-23 14:27:43

2

通过展示here文档是如何工作的另一种例子,前些天在IRB我写道:

require 'nokogiri' 
doc = Nokogiri.XML(<<ENDXML,&:noblanks) 
    ...gobs and gobs of pasted xml... 
ENDXML 

甚至更​​疯狂的是在一次传递多个HEREDOC字符串这一法律的语法:

p(<<END1, <<-END2, <<END3) 
    This indented text is part of 
    the first parameter, END1 
END1 
And this text is part of param2 
    whose ending sigil may be indented 
    END2 
and finally this text 
is part of 
the third parameter 
END3 
#=> " This indented text is part of\n the first parameter, END1\n" 
#=> "And this text is part of param2\n whose ending sigil may be indented\n" 
#=> "and finally this text\nis part of\nthe third parameter\n"