How do I create a directory ‘http://example.com’ without it getting
broken up because of the '/'s ?
url = ‘http://example1.com’
Dir.mkdir(url)
How do I create a directory ‘http://example.com’ without it getting
broken up because of the '/'s ?
url = ‘http://example1.com’
Dir.mkdir(url)
Comfort E. wrote:
How do I create a directory ‘http://example.com’ without it getting
broken up because of the '/'s ?
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.
Paul L. wrote:
Comfort E. wrote:
How do I create a directory ‘http://example.com’ without it getting
broken up because of the '/'s ?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?
Comfort E. wrote:
please state the problem to be solved and someone will help you.
Hmm, ok then. How could I strip http:// from that string?
string.sub!(%r{http://},"")
On 11/29/06, Comfort E. [email protected] wrote:
Hmm, ok then. How could I strip http:// from that string?
–
url = ‘http://example.com’
url.gsub!( /^http:///i, ‘’)
James
James B. wrote:
On 11/29/06, Comfort E. [email protected] wrote:
Hmm, ok then. How could I strip http:// from that string?
–
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
"
Troy D. wrote:
Does this work for you?
“http://www.test.com”.each do |url|
puts url.gsub!( /^http:///i, ‘’)
end
Yes. Re-evaluating my assumptions…
Comfort E. wrote:
/ …
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
What is “res”? Is it an array of strings?
Also, it is sometimes easier to use the %r{…} syntax instead of /…/,
this allows you to use “/” as an ordinary character.
Paul L. wrote:
Comfort E. wrote:
/ …
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, ‘’)
endWhat is “res”? Is it an array of strings?
I thought it was:
res = dbh.query(“Select url FROM sites”)
Comfort E. wrote:
Paul L. wrote:
Comfort E. wrote:
/ …
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, ‘’)
endWhat is “res”? Is it an array of strings?
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
Hi –
On Thu, 30 Nov 2006, Comfort E. wrote:
"
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
Paul L. wrote:
Comfort E. wrote:
"
while url = res.fetch_row do
puts url.gsub!( /^http:///i, ‘’)
endWell, it’s easy enough to find out.
Before you apply “gsub!”, test the class:
res = dbh.query(“Select url FROM sites”)
while url = res.fetch_row doputs 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.
Comfort E. wrote:
"
while url = res.fetch_row do
puts url.gsub!( /^http:///i, ‘’)
end
Well, it’s easy enough to find out.
Before you apply “gsub!”, test the class:
res = dbh.query(“Select url FROM sites”)
while url = res.fetch_row do
puts url.class # Add this. Read the result. Then decide what to do.
puts url.gsub!( /^http:\/\//i, '')
end
Chances are there’s a non-string in your incoming data.
Also “puts url.gsub!(…)” doesn’t make much sense. It returns nil if
there
were no substitutions (assuming “url” is a string), not what you want.
…
Array
All right. Now change “puts url.class” to “p url” to figure out what you
should do with those Arrays.
Devin
Devin M. wrote:
…
ArrayAll 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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs