Git Product home page Git Product logo

ruby-analyzer's Introduction

Exercism's Ruby Analyzer

Tests

This is Exercism's automated analyzer for the Ruby track.

It is run with ./bin/run.sh $EXERCISM $PATH_TO_FILES $PATH_FOR_OUTPUT and will read the source code from $PATH_TO_FILES and write a JSON file with an analysis to $PATH_FOR_OUTPUT.

For example:

./bin/run.sh two_fer ~/solution-238382y7sds7fsadfasj23j/ ~/solution-238382y7sds7fsadfasj23j/output/

Running the tests

Before running the tests, first install the dependencies:

bundle install

Then, run the following command to run the tests:

bundle exec rake test

ruby-analyzer's People

Contributors

dependabot[bot] avatar erikschierboom avatar exercism-bot avatar ihid avatar katrinleinweber avatar kntsoriano avatar kytrinyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-analyzer's Issues

Add comment when approving two-fer with interpolation

@kntsoriano I think this would be a good entry point into you understanding the automated mentoring stack.

At the moment we approve two-fer solutions when any of four string formats are used. For three (concatenation, string format and kernel format) we give a comment, but for interpolation we don't. However, it's become clear that we should.

To add this:

  • The two-fer analyzer needs changing to return a comment (probably called string_interpolation).
  • The test needs updating.
  • The website-copy repo needs a PR to add a markdown file in automated comments for the content.

Once the website-copy PR is merged, @ccare can show you how a new version of the analyzer gets built and deployed.

I think the content for website-copy should might be something like this:


String interpolation is a great way to build strings in Ruby. Another common way is using String#format, which is explained more in this article. For this solution that might look like:

"One for %%s, one for you" %% %{name_variable}"

Approvable solutions for Acronym

@iHiD

Per your request, here are the approvables for Acronym.
(Note that Acronym is not meeting all the requirements for a Level 1 exercise, (it's controversial, and it requires too many iterations to get it right), so when I find a better candidate it will move up in the track.)

  • Things that will be addressed later in the track, not on this level:

    • class or module : both approvable without comment
    • self. or class << self : both approvable without comment
  • Good solutions with split are auto-approvable; it would be nice to add a comment to investigate scan with regex /\b\w/.

  • Good solutions that have a too generic or typing name (input, string, str) for the param should preferrably have a comment about naming things, suggesting words or phrase.

  • One complete solution, approvable:

class Acronym
  def self.abbreviate(words)
    words.tr('-', ' ').split.map(&:chr).join.upcase
  end
end

Other approvables, method body only:

  • words.tr('-', ' ').split.map { |word| word.chr }.join.upcase

    • Symbol#to_proc is not relevant to this level, so the long form is auto-approvable.
    • Ignore spacing in block ({|word|...}) unless it's inconsistent : { |word| do_things}
    • Little bit controversial, but I would ignore double vs single quotes, especially if everything else is good. I'd mention it only when it's one of 3 or more style issues.
  • words.scan(/\b[[:alpha:]]/).join.upcase

    • plus other regexes: /\b\w/, /\b[a-zA-Z]/ , /\b[a-z]/i
    • (there are multiple regex's possible, most are covering not tested cases)
  • words.split(/[ -]/).map(&:chr).join.upcase

    • variants: split(/\W/),

Especially for this exercise, it may be interesting to see if non-approvables are easier to spot:

  • it will have word[0] within the block or word.slice(0)
  • and/or upcase is not at the end of the chain (note: there's one approvable that has upcase earlier).
  • and/or it will use gsub
  • and/or using each
  • and/or more than one line
  • plus a final check for join(

TwoFer: incorrect analysis

wrong_analysis

The analyzer mistakenly detects no module level method.

Also, Ruby doesn't really have "functions" but "methods". Closest thing to functions would be, I think, Proc or lambda.

Approvable solutions for High Scores

Auto-approvable:

class HighScores
  def initialize(scores)
    @scores = scores
  end

  def scores
    @scores
  end

  def personal_best
    scores.max
  end

  def latest
    scores.last
  end

  def personal_top_three
    scores.max(3)
  end
end

Approvable variants:

  • Use attr_reader (but not attr_accessor) instead of the scores getter method.

  • In personal_top_three, the following variants can be approved immediately, but with a comment to look into max(3):

    • scores.sort.reverse.first(3),
    • scores.sort.reverse.take(3)

All other variants are not eligible for auto-approval. Including a different order of the methods.

Add auto-approval for high scores

@ccare For you

Approvable solution without comment.

class HighScores
  attr_reader :scores

  def initialize(scores)
    @scores = scores
  end

  def personal_best
    scores.max
  end

  def latest
    scores.last
  end

  def personal_top_three
    scores.max(3)
  end
end

Approvable solution with comment (ruby.high-scores.attr_reader).

class HighScores
  def initialize(scores)
    @scores = scores
  end

  def scores
    @scores
  end

  def personal_best
    scores.max
  end

  def latest
    scores.last
  end

  def personal_top_three
    scores.max(3)
  end
end

Approvable solution with comment (ruby.high-scores.max_not_reverse and param of {method: 'take'}).

class HighScores
  def initialize(scores)
    @scores = scores
  end

  def scores
    @scores
  end

  def personal_best
    scores.max
  end

  def latest
    scores.last
  end

  def personal_top_three
    scores.reverse.take(3)
  end
end

Approvable solution with comment (ruby.high-scores.max_not_reverse and param of {method: 'first'}).

class HighScores
  def initialize(scores)
    @scores = scores
  end

  def scores
    @scores
  end

  def personal_best
    scores.max
  end

  def latest
    scores.last
  end

  def personal_top_three
    scores.reverse.first(3)
  end
end

@ccare You'll want to copy/paste the two-fer scaffolding to get started, then add one solution at a time. The key to developing this is to use pry. Reach out to @kytrinyx on Slack if you'd like her to talk you through this as she explained it to me :)

Add auto-approval for acronym

Various solutions are approvable. All have the following form:

class Acronym
  def self.abbreviate(words)
    ...
  end
end

The ... can then be any of the following:

# In this situation, approve with a comment that is ruby.acronym.block_syntax.shorthand
words.tr('-', ' ').split.map { |word| word.chr }.join.upcase

# We can just approve this without comment as a first pass.
words.tr('-', ' ').split.map(&:chr).join.upcase

# We can just approve this without comment as a first pass.
# We don't care what the content of of the regexp is.
words.scan(/\b[[:alpha:]]/).join.upcase

# We can just approve this without comment as a first pass.
# We don't care what the content of of the regexp is.
words.split(/[ -]/).map(&:chr).join.upcase

module or class are both valid (there's a helper for this)

@kntsoriano You'll want to copy/paste the two-fer scaffolding to get started, then add one solution at a time. The key to developing this is to use pry. Reach out to @kytrinyx on Slack if you'd like her to talk you through this as she explained it to me :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.