Heredoc क्या है
एक heredoc दो markers के बीच text का एक लंबा block लिखने का तरीका है, एक start और end line के बीच रखी एक letter की तरह। यह बड़े text pieces के लिए layout tidy रखता है।
In this page:
Syntax
text = <<~IDENTIFIER
first line
second line
IDENTIFIER
puts text
Heredoc
<<~IDENTIFIER से शुरू और अपनी line पर एक matching IDENTIFIER से खत्म होने वाला एक heredoc, आपको multi-line text का एक बड़ा, readable block लिखने देता है।
~ variant (squiggly heredoc) automatically leading indentation strip करता है, heredoc को surrounding code के साथ nicely indented रखना आसान बनाते हुए। Heredocs double-quoted strings जैसे string interpolation support करते हैं।
Note:
older
<<- से <<~ (squiggly heredoc) prefer करें क्योंकि यह automatically common leading whitespace strip करता है।उदाहरण: Heredoc
name = "World"
text = <<~GREETING
Hello, #{name}!
This is a heredoc.
It can span many lines.
GREETING
puts text
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. #}
आम गलतियां
<<-या<<इस्तेमाल करना और indentation हटने की उम्मीद करना, जब सिर्फ<<~common indent strip करता है।- closing identifier को
<<~की बजाय<<से indent करना, इसलिए यह recognised नहीं होता। - identifier को
<<~EOSकी तरह quote करना और#{name}के काम करने की उम्मीद करना, जब यह interpolation रोकता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: