D
Douglas Wells
I'm writing a number of test cases. I would like the input data to
behave like a file, and I would like to include that data within
the test file (in order to reduce the proliferation of files and
eliminate the necessity of tracking an additional, separate file
for each test case). Similar mechanisms would include BASIC's
DATA statements, or Perl's DATA filehandle. I don't know of an
analogue in ruby. Any suggestions?
Instead I am using Bourne shell-type here-documents. But, I am
encountering a problem. The Bourne shell supports the concept of
stripping leading white space, and Ruby seems to support the same
notion (from .../doc/ruby18/ruby-man/syntax.html):
"If the - [is] placed before the delimiter, then all leading
whitespcae [sic] characters (tabs or spaces) are stripped from
input lines and the line containing [the] delimiter. This
allows here-documents within scripts to be indented in a natural
fashion."
which is the same syntax as the Bourne shell.
But, if I run the following script:
# Start of script:
input1 = <<EOF
abc
def
EOF
input2 = <<-EOF
ghi
jkl
EOF
p input1
p input2
# End of script.
I get the following output:
"abc\ndef\n"
"\tghi\n\tjkl\n"
Note that the leading tab has NOT been removed in the here-document
that should be stripped (input2). (It is a tab in the original file.)
Is this a bug? or am I missing something in the documentation.
I'm using 'ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-freebsd6]'.
(And yes, I know how to strip the leading whitespace with a function
after reading it. I'm particularly addressing the issue with here
documents.)
Thanks, - dmw
behave like a file, and I would like to include that data within
the test file (in order to reduce the proliferation of files and
eliminate the necessity of tracking an additional, separate file
for each test case). Similar mechanisms would include BASIC's
DATA statements, or Perl's DATA filehandle. I don't know of an
analogue in ruby. Any suggestions?
Instead I am using Bourne shell-type here-documents. But, I am
encountering a problem. The Bourne shell supports the concept of
stripping leading white space, and Ruby seems to support the same
notion (from .../doc/ruby18/ruby-man/syntax.html):
"If the - [is] placed before the delimiter, then all leading
whitespcae [sic] characters (tabs or spaces) are stripped from
input lines and the line containing [the] delimiter. This
allows here-documents within scripts to be indented in a natural
fashion."
which is the same syntax as the Bourne shell.
But, if I run the following script:
# Start of script:
input1 = <<EOF
abc
def
EOF
input2 = <<-EOF
ghi
jkl
EOF
p input1
p input2
# End of script.
I get the following output:
"abc\ndef\n"
"\tghi\n\tjkl\n"
Note that the leading tab has NOT been removed in the here-document
that should be stripped (input2). (It is a tab in the original file.)
Is this a bug? or am I missing something in the documentation.
I'm using 'ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-freebsd6]'.
(And yes, I know how to strip the leading whitespace with a function
after reading it. I'm particularly addressing the issue with here
documents.)
Thanks, - dmw