你如何有一个没有前导空格的多行字符串并且仍然与方法正确对齐?以下是我的一些尝试。正在工作的那个不是很有趣...
module Something
def welcome
"
Hello
This is an example. I have to write this multiline string outside the welcome method
indentation in order for it to be properly formatted on screen. :(
"
end
end
module Something
def welcome
"
Hello
This is an example. I am inside welcome method indentation but for some reason
I am not working...
".ljust(12)
end
end
module Something
def welcome
"Hello\n\n"+
"This is an example. I am inside welcome method indentation and properly"+
"formatted but isn't there a better way?"
end
end
更新
code = <<-END.gsub(/^\s+\|/, '')
|def test
| some_method
| other_method
|end
END
# => "def test\n some_method\n other_method\nend\n"