creating directory "http://example.com"

C

Comfort Eagle

Paul said:
Very simply, you can't. That is an URL, not a directory path.

Insteda of asking this hypothetical question about a hypothetical
solution,
please state the problem to be solved and someone will help you.

Hmm, ok then. How could I strip http:// from that string?
 
C

Comfort Eagle

James said:
url = 'http://example.com'
url.gsub!( /^http:\/\//i, '')



James

Interesting. Newb Q, I'm sure, but when I put that in a while loop I
get: "private method `gsub!' called for ..." /me googles & still
scratches head.

"
res.each do |url|
puts url.gsub!( /^http:\/\//i, '')
end
"
 
C

Comfort Eagle

Better:
I thought it was array of strings & looks like it to me??

res = dbh.query("Select url FROM sites")
while url = res.fetch_row do
puts url.gsub!( /^http:\/\//i, '')
end
 
D

dblack

Hi --

Interesting. Newb Q, I'm sure, but when I put that in a while loop I
get: "private method `gsub!' called for ..." /me googles & still
scratches head.

"
res.each do |url|
puts url.gsub!( /^http:\/\//i, '')
end
"

It sounds like you've got something other than strings -- or at least
one thing that isn't a string -- in your array. gsub(!) is sort of
weird because, even though it's only for strings, every object has the
method. That's because it's a "top-level" method... and *that's*
because it defaults to operating on $_, the default variable.

Anyway, mainly you just need to figure out what non-string is being
assigned to your url variable.


David

--
David A. Black | (e-mail address removed)
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
 
C

Comfort Eagle

Paul said:
Well, it's easy enough to find out.

Before you apply "gsub!", test the class:


puts url.class # Add this. Read the result. Then decide what to do.

Brilliant. Here's the output:
Array
Array
Array
Array
Array

Definitely not strings.
 
D

Devin Mullins

Before you apply "gsub!", test the class:
Brilliant. Here's the output:
Array
...
Array

All right. Now change "puts url.class" to "p url" to figure out what you
should do with those Arrays.

Devin
 
C

Comfort Eagle

Devin said:
All right. Now change "puts url.class" to "p url" to figure out what you
should do with those Arrays.

Devin

url = row[0] fixed that right up.

Thanks everyone.
 

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
474,219
Messages
2,571,118
Members
47,733
Latest member
BlairMeado

Latest Threads

Top