← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 6 of 7

Comments क्या हैं

एक comment मनुष्यों के लिए एक note है जो एक hash mark से शुरू होता है और Ruby इसे ignore करता है। यह एक recipe के margin में एक sticky note जैसा है।

In this page:

  1. Comments
Syntax
ruby
# 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

markup
# 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"
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. #}
आम गलतियां
  1. comments के लिए // इस्तेमाल करना, जो Ruby में एक syntax error है; # इस्तेमाल करें।
  2. =begin और =end को spaces के बाद रखना, जब उन्हें line की बिल्कुल शुरुआत में होना ज़रूरी है।
  3. =end भूल जाना, जो बाकी पूरी file को comment कर देता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.