Skip to content

Approvable solutions for Acronym #11

Open
@emcoding

Description

@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(

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions