Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Only two things really jumped out at me.</p> <pre><code>qry_a = @qry.split(sep) </code></pre> <p>The variable on the above line is local, and only comes into existence within the <code>else</code> clause, yet you refer to it again later.</p> <pre><code>@qry = URI.unescape(qry) </code></pre> <p>The use of an instance variable isn't needed unless you have an object, and I'd suggest it is a problem as it immediately opens up the scope of the variable beyond the method. Personally, I try to use locals as much as possible.</p> <p>Aside from that, it seems fine to me. Perhaps you could've used a test framework like Minitest or RSpec for the tests, but it seems fine in style.</p> <p>I agree with @mcfinnigan that more specific points would've been more helpful to you.</p> <hr> <p>I'll add (as I was a bit hasty), using array indices directly is also not such great style, as it gets confusing quickly. For example, this looks like Perl i.e. line noise :)</p> <pre><code>rtn[pair[0]] &lt;&lt; pair[1] ||= "" </code></pre> <p>You've also used <code>each</code> to affect a value when something like <code>map</code> or <code>select</code> might be better, as they explicitly affect value instead of doing it as a side effect. Being clear and explicit is good style in Ruby (IMO).</p> <hr> <p>One more thought… (my coffee is kicking in:) Since this was a job interview, perhaps they were looking for something beyond this. For example, my first thought upon seeing the spec was "why pass the string as an argument?" You may have been better doing something like:</p> <pre><code>class String def query_to_hash( separator="&amp;" ) # more code </code></pre> <p>and then it could be called from <code>"foo=bar&amp;abc=1%202%203".query_to_hash</code>, which is <em>far</em> more Rubyish.</p> <p>Even better than a monkeypatch, inheritance (too often overlooked).</p> <pre><code>class QueryString &lt; String def to_hash( separator="&amp;" ) # some code that refers to `self` </code></pre> <p>and then it could be used via:</p> <pre><code>QueryString.new("foo=bar&amp;abc=1%202%203").to_hash </code></pre> <p>which is far clearer to read and understand and makes much clearer <em>what you are trying to achieve</em>. There are other ways to do this too, and perhaps that is what would separate you from the crowd.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload