[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Legal syntax, bug or what?

Jonathan Maasland

9/1/2006 9:04:00 AM

Hi all,

I'm still working on Ripper and during my explorations I came across a
line of code in mkmf.rb that I can't wrap my head around.

Line 1313
---
opts = $arg_config.collect {|t, n| "\t#{t}#{"=#{n}" if n}\n"}
---

When I copy-paste the entire method to a file and run it through Ruby
everything is fine.
However irb doesn't accept the method:
----
irb(main):001:0> def mkmf_failed(path)
irb(main):002:1> unless $makefile_created or File.exist?("Makefile")
irb(main):003:2> opts = $arg_config.collect {|t, n| "\t#{t}#{"=#{n}"
if n}\n"}
irb(main):004:3* abort "*** #{path} failed ***\n" + FailedMessage +
opts.join
irb(main):005:3> end
irb(main):006:2> end
irb(main):007:1>
------
As you can see irb doesn't detect the end of the third line.

After taking the statement apart and simplifying it, it all boils down
to the following construction:
#{"=#{n}" if n}
inside the ""main"" double-quoted string.

Why does ruby accept this construct while irb doesn't?
Doesn't Ruby see the first double-quote as the end of the string?

Any clarification would be greatly appreciated.

With kind regards
Jonathan Maasland

1 Answer

dblack

9/1/2006 10:35:00 AM

0