addis_a
1
Why the string interpolation is not working inside the Nokogiri method
#search
?
require ‘nokogiri’
doc = Nokogiri::HTML::Document.parse <<-eotl
eotl
doc.class # => Nokogiri::HTML::Document
class Person
attr_accessor :name
end
ram = Person.new
ram.name=“foo”
ram.name # => “foo”
doc.search(’//div/p[text()= “#{ram.name}”]’).to_a.size
=> 0
Where am I doing wrong ? please help!
my-ruby
2
On Mon, Sep 2, 2013 at 1:29 PM, Love U Ruby [email protected]
wrote:
ram.name # => "foo"
doc.search('//div/p[text()= "#{ram.name}"]').to_a.size
# => 0
Where am I doing wrong ? please help!
You are not wrapping it in a “” or %Q{}…:
- doc.search(“//div/p[text()= "#{ram.name}"]”).to_a.size
- doc.search(%Q{//div/p[text()= “#{ram.name}”]}).to_a.size
my-ruby
3
@Jordon - Thank you very much - it worked like a charm!!
require ‘nokogiri’
doc = Nokogiri::HTML::Document.parse <<-eotl
eotl
doc.class # => Nokogiri::HTML::Document
class Person
attr_accessor :name
end
ram = Person.new
ram.name=“foo”
ram.name # => “foo”
doc.search("//div/p[text()= “#{ram.name}”]").to_a.size
=> 2