R
Richard Lionheart
As I read Thomas&Hunt p. 205, Ruby should build a quoted string with the
text from <<XXX to the next XXX. But that doesn't happen with some quoted
strings in that block, as follows. Why?
# F:\_Projects_Current\_Projects_Ruby\A009-Comments\Comments.rb
for i in 1..3
puts i.to_s
end
print <<TEST
xxxx
yyyy
"abc"
class A
def initialize(*args, &block)
puts '---'
puts "args <#{ args.inspect }>"
block.call if block
end
end
TEST
<<OUTPUT
1
2
3
Comments.rb:15: undefined local variable or method `args' for main:Object
(NameError)
text from <<XXX to the next XXX. But that doesn't happen with some quoted
strings in that block, as follows. Why?
# F:\_Projects_Current\_Projects_Ruby\A009-Comments\Comments.rb
for i in 1..3
puts i.to_s
end
print <<TEST
xxxx
yyyy
"abc"
class A
def initialize(*args, &block)
puts '---'
puts "args <#{ args.inspect }>"
block.call if block
end
end
TEST
<<OUTPUT
Testruby Comments.rb
1
2
3
Comments.rb:15: undefined local variable or method `args' for main:Object
(NameError)
OUTPUTExit code: 1