Analysis of DATA Objects in Ruby and RubyDATA objects

Source: Internet
Author: User

Analysis of DATA Objects in Ruby and RubyDATA objects

Can this code be run? What is this DATA?

Require 'erb' data = DATA. readmax = 15_000title = "hello world! "Content =" hello world! \ N "* 10max. times {ERB. new (data ). result (binding )} __end __< html> 

This magic DATA is an IO object, read_ END __Content. Note thatDATA. readWill_ END __The subsequent content is read at one time. Due to the IO reading feature, whenDATA. readThe content will be empty. If you need to read the content for the second time, you must first executeDATA. rewind.

Sometimes we write a script to do some automation work. We need to read the content of a file in advance. As an input or as a template, We can first attach this part of content_ END __And then useDATABecause it is a standard IO object, we can process it like a normal file._ END __Content, as shown in the code above, used to storeERBIt is very convenient to use the content as a template and then process it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.