DEV Community

Cover image for Exercism Ruby - Two Fer
Juan Vasquez
Juan Vasquez

Posted on • Edited on

1

Exercism Ruby - Two Fer

Alt Text

Two-fer or 2-fer is short for two for one. One for you and one for me.

"One for X, one for me."
Enter fullscreen mode Exit fullscreen mode

When X is a name or "you".

If the given name is "Alice", the result should be "One for Alice, one for me." If no name is given, the result should be "One for you, one for me."

Source wikipedia Two-fer


require 'minitest/autorun'
require_relative 'two_fer'

# Common test data version: 1.2.0 4fc1acb
class TwoFerTest < Minitest::Test
  def test_no_name_given
    assert_equal "One for you, one for me.", TwoFer.two_fer
  end

  def test_a_name_given
    assert_equal "One for Alice, one for me.", TwoFer.two_fer("Alice")
  end

  def test_another_name_given
    assert_equal "One for Bob, one for me.", TwoFer.two_fer("Bob")
  end
end
Enter fullscreen mode Exit fullscreen mode
class TwoFer
  def self.two_fer name = "you"
    "One for #{name}, one for me."
  end
end
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more