Dir.glob ['*.#{variable}'] Not working

I’ve got a problem with displaying files of a same extension

The source code:
http://pastebin.com/6gkRdW2j

Please be simple as you can while explaining, I’m not an English men.

Your help is appreciated, Thank you.

Hello,

didn’t run the code but when using interpolation you have to use “”
(double quotes) and not ‘’ (single quotes) like:

Dir.glob [".#{ext}"] instead of Dir.glob [’.#{ext}’]
On 31 Ιαν 2014, at 08:45 , cynic limbu [email protected] wrote:


Posted via http://www.ruby-forum.com/.

Panagiotis (atmosx) Atmatzidis

email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5

You can also use Dir[] instead of Dir.glob()

And you can build your variable before passing it to Dir[] such as via

x = ‘foo/’
x << ‘*’
Dir[x]

The variant #{x} is really only useful in a String.
Dir["#{x}"] is unnecessary.

Panagiotis A. wrote in post #1135144:

Hello,

didn’t run the code but when using interpolation you have to use “”
(double quotes) and not ‘’ (single quotes) like:

Dir.glob [".#{ext}"] instead of Dir.glob [’.#{ext}’]

Oh my god, thank you very much.

I tried all possible combination but how could i not think of that. Once
again, thanks.

On Fri, Jan 31, 2014 at 8:45 AM, cynic limbu [email protected]
wrote:

I’ve got a problem with displaying files of a same extension

The source code:
http://pastebin.com/6gkRdW2j

There are two issues

  • You are trying to use string interpolation with single quotes (you
    need double quotes).
  • You are mixing two approaches with the square brackets and Dir#glob

irb(main):005:0> ext = “sh”
=> “sh”
irb(main):006:0> Dir[".#{ext}"]
=> [“args.sh”, “backup-rsync.sh”, “java-exec.sh”, “jobs.sh”, “loc.sh”,
“mwg-saas-props.sh”]
irb(main):007:0> Dir.glob("
.#{ext}")
=> [“args.sh”, “backup-rsync.sh”, “java-exec.sh”, “jobs.sh”, “loc.sh”,
“mwg-saas-props.sh”]

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs