Skip to content

Instantly share code, notes, and snippets.

@lrjbrual
Last active April 26, 2016 14:01
Show Gist options
  • Save lrjbrual/5bf90c65e738070d3d2925b62f70936d to your computer and use it in GitHub Desktop.
Save lrjbrual/5bf90c65e738070d3d2925b62f70936d to your computer and use it in GitHub Desktop.
Solution for Interpolation .to_s ("String") via Robocop
======= Problem with codes using interpolation #{url}====
lapse Offence from Robocop: C: 12: 32: Prefer to_s over string interpolation.
-------------------------
require 'nokogiri'
require 'open-uri'
class Browser
attr_accessor :url
def initialize
@url = url
end
def fetch_content(url)
html = Nokogiri::HTML(open("#{url}"))
return html.at('body').inner_text
end
end
===========
Solution: inside the method of fetch_content(url), remove the interpolation and add .to_s
like: html = Nokogiri::HTML(open(url.to_s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment