benjohn
1/17/2007 9:31:00 AM
The library looks groovy.
But I never knew that block quoted strings worked like this:
> args = Getopt::Declare.new(<<'EOF')
> -q, --quiet quiet
> -f, --files <files:if>... input files
> -n, --number <num:n> a float number
> -i, --integer <num:i> an integer number
> EOF
That's just completely cool! And it also makes a lot of sense: I think
I'll actually remember it now.
You can do somethin like this:
irb(main):008:0> puts <<'STRING_END'.gsub('a') {'XXX'}
irb(main):009:0' bab
irb(main):010:0' aba
irb(main):011:0' STRING_END
bXXXb
XXXbXXX
You can even do this (discovered just now in one of those, "surely this
wont work too, will it?" Ruby moments)!...
irb(main):015:0> puts <<BLOCK_ONE_END + <<BLOCK_TWO_END
irb(main):016:0" hello
irb(main):017:0" there
irb(main):018:0" BLOCK_ONE_END
irb(main):019:0" and how about
irb(main):020:0" some more?
irb(main):021:0" BLOCK_TWO_END
hello
there
and how about
some more?
Brilliant!
Anyone know when you do and don't need to place ''s around the string
terminator?
Cheers,
Benjohn