Created
June 25, 2013 22:20
-
-
Save yeehaa123/5862997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/spec' | |
require 'minitest/autorun' | |
describe Integer do | |
describe "#in_words" do | |
it "should return four for 4" do | |
4.in_words.must_equal "four" | |
end | |
it "should return twenty seven for 27" do | |
27.in_words.must_equal "twenty seven" | |
end | |
end | |
end | |
class Integer | |
def in_words | |
number_words = [ | |
[20, "twenty"], | |
[19, "nineteen"], | |
[18, "eighteen"], | |
[17, "seventeen"], | |
[16, "sixteen"], | |
[15, "fifteen"], | |
[14, "fourteen"], | |
[13, "thirteen"], | |
[12, "twelve"], | |
[11, "eleven"], | |
[10, "ten"], | |
[9, "nine"], | |
[8, "eight"], | |
[7, "seven"], | |
[6, "six"], | |
[5, "five"], | |
[4, "four"], | |
[3, "three"], | |
[2, "two"], | |
[1, "one"] | |
] | |
word_number = "" | |
number_words.each {|number, word| word_number = word if self == number } | |
word_number | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment