Comments क्या हैं
एक comment मनुष्यों के लिए एक note है जो एक hash mark से शुरू होता है और Ruby इसे ignore करता है। यह एक recipe के margin में एक sticky note जैसा है।
In this page:
Syntax
# single-line comment
value = 1 # trailing comment
=begin
block comment
=end
Comments
Ruby में एक # एक single-line comment शुरू करता है, और उस line पर इसके बाद सब कुछ ignore होता है। Multi-line comments =begin और =end इस्तेमाल करते हैं, हालाँकि practice में single-line # comments कहीं ज़्यादा common हैं।
Comments को non-obvious reasoning explain करना चाहिए, जो code already clear बनाता है वह दोहराना नहीं।
Note:
ज़्यादातर Ruby style guides कई
# lines के पक्ष में =begin/=end blocks discourage करती हैं।उदाहरण: Comments
# This script demonstrates comments
puts "Hello!" # inline comment after code
=begin
This is a multi-line comment block,
though single-line # comments are more idiomatic.
=end
puts "Still running"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- comments के लिए
//इस्तेमाल करना, जो Ruby में एक syntax error है;#इस्तेमाल करें। =beginऔर=endको spaces के बाद रखना, जब उन्हें line की बिल्कुल शुरुआत में होना ज़रूरी है।=endभूल जाना, जो बाकी पूरी file को comment कर देता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: