hi
sorry!
i can not speak english well..
This is how I know...
"abcdef".gsub(/c/) {|h| puts h}
but, Why do I get an error that my code..
this is my code
require 'net/http'
page= Net::HTTP.new(‘www.google.co.kr’,80)
reg = page.get('/index.html')
reg.gsub(/a/) {|gg| puts gg}
puts reg
thank you...
···
--
Posted via http://www.ruby-forum.com/.
String#gsub does string substitution, but it cannot replace /a/ with
nil, and the return value of 'puts' is nil.
Maybe you want to try String#scan instead, like this:
p reg.scan(/a/)
^ manveru
···
On Sat, Aug 30, 2008 at 2:59 PM, Hwang In-seok <his2000x@gmail.com> wrote:
hi
sorry!
i can not speak english well..
This is how I know...
"abcdef".gsub(/c/) {|h| puts h}
but, Why do I get an error that my code..
this is my code
require 'net/http'
page= Net::HTTP.new('www.google.co.kr’,80)
reg = page.get('/index.html')
reg.gsub(/a/) {|gg| puts gg}
puts reg
thank you...
Michael Fellinger wrote:
p reg.scan(/a/)
^ manveru
thank you...
but, 'gsub' and 'scan' both have the same error.
error is....
http.rb:9: private method `scan' called for #<Net::HTTPOK 200 OK
readbody=true> (NoMethodError)
private method is what mean??
i don't understand...
please teach me.
···
--
Posted via http://www.ruby-forum.com/\.
This is your code :
require 'net/http'
page= Net::HTTP.new(‘www.google.co.kr’,80)
reg = page.get('/index.html')
reg.gsub(/a/) {|gg| puts gg}
puts reg
Your are trying to use gsub on the object returned by Net::HTTP , which
isn't a string . Your code should look like this :
require 'net/http'
page= Net::HTTP.new(‘www.google.co.kr’,80)
reg = page.get('/index.html')
reg.body.gsub!(/a/) {|gg| puts gg}
puts reg.body
Pay attention to the gsub! , which modifies the string in-place .Judging
by your script,that is what you want .
···
--
Posted via http://www.ruby-forum.com/.