I started picking up ruby for rails, so here is my shining gem.
Try it out here
word.rb
class Word @@alphabet = ('a'..'z').to_a def self.to_mark(word) word.chars.sum { |char| @@alphabet.index(char.downcase) + 1 } end end
word_test.rb
require 'minitest/autorun' require_relative 'word' class TestWord < Minitest::Test def setup @cases = [ { input: 'love', expected: 54 }, { input: 'friendship', expected: 108 }, { input: 'attitude', expected: 100 }, { input: 'friends', expected: 75 }, { input: 'family', expected: 66 }, { input: 'selflessness', expected: 154 }, { input: 'knowledge', expected: 96 } ] end def test_to_mark @cases.each { |test| assert_equal test[:expected], Word.to_mark(test[:input]) } end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I started picking up ruby for rails, so here is my shining gem.
Try it out here
word.rb
word_test.rb