वहाँ रूबी में बहु लाइन स्ट्रिंग को परिभाषित करने के विभिन्न तरीके हैं। यह उनमें से एक है।
> name = 'John'
> city = 'Ny'
> multiline_string = <<-EOS
> This is the first line
> My name is #{name}.
> My city is #{city} city.
> EOS
=> "This is the first line\nMy name is John.\nMy city is Ny city.\n"
>
ऊपर के उदाहरण में EOS
सिर्फ एक सम्मेलन, आप अपनी पसंद के किसी भी स्ट्रिंग और उसके केस संवेदी का उपयोग कर सकते है। आम तौर पर EOS
का अर्थ है End Of String
इसके अलावा, -
(डैश) की आवश्यकता नहीं है। हालांकि, आपको "यहां दस्तावेज़ का अंत" डिलीमीटर प्रस्तुत करने की अनुमति देता है। वाक्यों को समझने के लिए निम्न उदाहरण देखें।
2.2.1 :014 > <<EOF
2.2.1 :015"> My first line without dash
2.2.1 :016"> EOF
2.2.1 :017"> EOF
=> "My first line without dash\n EOF\n"
2.2.1 :018 > <<-EOF
2.2.1 :019"> My first line with dash. This even supports spaces before the ending delimiter.
2.2.1 :020"> EOF
=> "My first line with dash. This even supports spaces before the ending delimiter.\n"
2.2.1 :021 >
अधिक जानकारी के लिए देख https://cbabhusal.wordpress.com/2015/10/06/ruby-multiline-string-definition/
यह गहरे लाल रंग का हियरडॉक वाक्य-विन्यास है। आप इसके बारे में यहां पढ़ सकते हैं: http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html –