Last active
April 26, 2016 14:01
-
-
Save lrjbrual/5bf90c65e738070d3d2925b62f70936d to your computer and use it in GitHub Desktop.
Solution for Interpolation .to_s ("String") via Robocop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
======= 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