루비의 여러 줄 설명?
루비에서 여러 줄을 댓글로 달려면 어떻게 해야 하나요?
#!/usr/bin/env ruby
=begin
Every body mentioned this way
to have multiline comments.
The =begin and =end must be at the beginning of the line or
it will be a syntax error.
=end
puts "Hello world!"
<<-DOC
Also, you could create a docstring.
which...
DOC
puts "Hello world!"
"..is kinda ugly and creates
a String instance, but I know one guy
with a Smalltalk background, who
does this."
puts "Hello world!"
##
# most
# people
# do
# this
__END__
But all forgot there is another option.
Only at the end of a file, of course.
- (스크린샷을 통해) 이렇게 표시됩니다. 그렇지 않으면 위의 설명이 어떻게 표시될지 해석하기 어렵습니다.확대하려면 클릭:
=begin
My
multiline
comment
here
=end
있음에도 불구하고=begin
그리고.=end
일반적이고 더 정확한 논평 방법은 사용하는 것입니다.#
각 라인에 있습니다.루비 라이브러리의 원본을 읽으면 거의 모든 경우에 다중 줄 주석이 수행되는 방식을 알 수 있습니다.
#!/usr/bin/env ruby
=begin
Between =begin and =end, any number
of lines may be written. All of these
lines are ignored by the Ruby interpreter.
=end
puts "Hello world!"
다음 중 하나 사용:
=304이것.이라a댓글블록=끝
또는
이이라a의코멘트블록
현재 rdoc에서 지원하는 것은 2개뿐이며, 이것들만 사용하는 것이 좋은 이유라고 생각합니다.
=begin
comment line 1
comment line 2
=end
확실하게=begin
그리고.=end
그 줄의 첫 번째 것입니다(공백 없음).
다음은 예입니다.
=begin
print "Give me a number:"
number = gets.chomp.to_f
total = number * 10
puts "The total value is : #{total}"
=end
당신이 그 사이에 두는 모든 것=begin
그리고.=end
포함된 코드 줄 수에 관계없이 주석으로 처리됩니다.
참고: 사이에 공간이 없어야 합니다.=
그리고.begin
:
- 정답:
=begin
- 틀렸습니다:
= begin
=begin
(some code here)
=end
그리고.
# This code
# on multiple lines
# is commented out
둘 다 맞습니다.첫 번째 주석 유형의 장점은 편집 가능성입니다. 삭제되는 문자 수가 적기 때문에 주석을 달기가 쉽습니다.두 번째 유형의 주석은 읽기 쉽다는 장점이 있습니다. 코드를 한 줄씩 읽어보면 특정 행이 주석 처리되었음을 훨씬 쉽게 알 수 있습니다.여러분의 전화지만 누가 여러분을 쫓아오고 있는지, 그리고 그들이 읽고 유지하는 것이 얼마나 쉬운지 생각해 보세요.
Ruby on Rails에서 HTML 템플릿의 여러 줄에 주석을 다는 방법을 찾고 있는 경우, 예를 들어 다음과 같은 =timeout =end에 문제가 있을 수 있습니다.
<%
=begin
%>
... multiple HTML lines to comment out
<%= image_tag("image.jpg") %>
<%
=end
%>
%> image_tag 닫기 때문에 실패합니다.
이 경우, 이것이 주석을 다는 것인지 아닌지는 논쟁의 여지가 있을 수 있지만, 저는 원하지 않는 섹션을 "거짓일 경우" 블록으로 둘러싸는 것을 선호합니다.
<% if false %>
... multiple HTML lines to comment out
<%= image_tag("image.jpg") %>
<% end %>
이것은 효과가 있을 거예요.
def idle
<<~aid
This is some description of what idle does.
It does nothing actually, it's just here to show an example of multiline
documentation. Thus said, this is something that is more common in the
python community. That's an important point as it's good to also fit the
expectation of your community of work. Now, if you agree with your team to
go with a solution like this one for documenting your own base code, that's
fine: just discuss about it with them first.
Depending on your editor configuration, it won't be colored like a comment,
like those starting with a "#". But as any keyword can be used for wrapping
an heredoc, it is easy to spot anyway. One could even come with separated
words for different puposes, so selective extraction for different types of
documentation generation would be more practical. Depending on your editor,
you possibly could configure it to use the same syntax highlight used for
monoline comment when the keyword is one like aid or whatever you like.
Also note that the squiggly-heredoc, using "~", allow to position
the closing term with a level of indentation. That avoids to break the visual reading flow, unlike this far too long line.
aid
end
게시 순간 스택 오버플로 엔진이 구문 색상을 올바르게 렌더링하지 않습니다.선택한 편집기에서 렌더링하는 방법을 테스트하는 것은 연습으로 허용됩니다.;)
언급URL : https://stackoverflow.com/questions/2989762/multi-line-comments-in-ruby
'programing' 카테고리의 다른 글
는 "HttpRequest"에 대한 상수입니다.RequestType" 및 "WebRequest"를 선택합니다..NET의 Method" 값? (0) | 2023.07.06 |
---|---|
TypeScript | Array.from | 오류 TS2339: 'from' 속성이 'ArrayConstructor' 유형에 없습니다. (0) | 2023.07.06 |
헤로쿠가 비마스터 깃 지점을 실행 (0) | 2023.07.06 |
.bashrc, .bash_profile 및 .environment의 차이점은 무엇입니까? (0) | 2023.07.01 |
Global.asax에서 Application_Start와 Init을 사용하는 경우 (0) | 2023.07.01 |