nesting #{} problem

M

Martin Pirker

Hello...

irb(main):040:0> width = nil
=> nil
irb(main):041:0> "door#{" and width #{width}" if width}"
=> "door"
irb(main):042:0> width = 99
=> 99
irb(main):043:0> "door#{" and width #{width}" if width}"
=> "door and width 99"
irb(main):044:0> "door#{" and width=#{width}" if width}"
irb(main):045:0*


I'm stuck :-/

- why does the = change something - other chars work?
- how to fix it?


Thanks!
Martin
 
A

Austin Ziegler

Hello...

irb(main):040:0> width = nil
=> nil
irb(main):041:0> "door#{" and width #{width}" if width}"
=> "door"
irb(main):042:0> width = 99
=> 99
irb(main):043:0> "door#{" and width #{width}" if width}"
=> "door and width 99"
irb(main):044:0> "door#{" and width=#{width}" if width}"
irb(main):045:0*

I'm stuck :-/

- why does the = change something - other chars work?
- how to fix it?

The problem is partially in irb. Your code works if you put it in a Ruby file
and go from there. However, your code will be easier to understand and even irb
gets it if you switch one of the two quoted strings to use an
alternative quote, e.g.,

irb(main):001:0> width = nil
=> nil
irb(main):002:0> %Q(door#{" and width #{width}" if width})
=> "door"
irb(main):003:0> %Q(door#{" and width=#{width}" if width})
=> "door"
irb(main):004:0> width = 99
=> 99
irb(main):005:0> %Q(door#{" and width #{width}" if width})
=> "door and width 99"
irb(main):006:0> %Q(door#{" and width=#{width}" if width})
=> "door and width=99"

-austin
 
M

Martin Pirker

Austin Ziegler said:
The problem is partially in irb [...]
if you switch one of the two quoted strings to use an alternative quote,

works - thanks!

I still consider irb and .to_yaml the most useful testing tools, tripping on
an irb issue can happen :)

Martin


PS: Sadly, of the replies only 107141 and 107155 made it to my point of
NNTP world, 107[140|144|147|148] seem to be lost - bad ratio :-/
Google groups has all 6 replies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top