diff --git a/00_hello/hello.rb b/00_hello/hello.rb new file mode 100644 index 000000000..dab7f96c9 --- /dev/null +++ b/00_hello/hello.rb @@ -0,0 +1,8 @@ + +def hello + "Hello!" +end + +def greet(person_name) + "Hello, #{person_name}!" +end diff --git a/00_hello/hello_spec.rb b/00_hello/hello_spec.rb index 26075944a..d4700249b 100644 --- a/00_hello/hello_spec.rb +++ b/00_hello/hello_spec.rb @@ -113,7 +113,7 @@ # "Hello, #{who}!" # end # -require "hello" +require_relative "hello" describe "the hello function" do it "says hello" do diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb new file mode 100644 index 000000000..c0cf06ced --- /dev/null +++ b/01_temperature/temperature.rb @@ -0,0 +1,8 @@ + +def ftoc(temp) + ((temp - 32)/1.8).round +end + +def ctof(temp) + (temp * 1.8) + 32 +end diff --git a/01_temperature/temperature_spec.rb b/01_temperature/temperature_spec.rb index 7e92a54dc..3fda38e12 100644 --- a/01_temperature/temperature_spec.rb +++ b/01_temperature/temperature_spec.rb @@ -15,7 +15,7 @@ # 1.0 / 2.0 => 0.5 # -require "temperature" +require "./temperature" describe "temperature conversion functions" do diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb new file mode 100644 index 000000000..820e7aed6 --- /dev/null +++ b/02_calculator/calculator.rb @@ -0,0 +1,38 @@ +def add(num1, num2) + num1 + num2 +end + +def subtract(num1, num2) + num1 - num2 +end + +def sum(array) + sum = 0 + array.each {|num| sum += num } + sum +end + + +def multiply(*num) + product = 1 + num.each { |n| product *= n } + product +end + + +def power(num1, num2) + num1 ** num2 +end + + +def factorial(num) + if num == 0 || num == 1 + 1 + elsif num == 2 + 2 + else + product = 1 + (1..num).each {|num| product *= num} + product + end +end diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index fef7e9d00..7fe3ac686 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -33,7 +33,7 @@ # # -require "calculator" +require_relative "calculator" describe "add" do it "adds 0 and 0" do @@ -77,23 +77,44 @@ # once the above tests pass, # write tests and code for the following: -describe "#multiply" do +describe "multiply" do - it "multiplies two numbers" + it "multiplies two numbers" do + expect(multiply(3, 6)).to eq(18) + end + + it "multiplies several numbers" do + expect(multiply(3,4,5,5)).to eq(300) + end - it "multiplies several numbers" - end -describe "#power" do - it "raises one number to the power of another number" + +describe "power" do + it "raises one number to the power of another number" do + expect(power(3,4)).to eq(81) + end end # http://en.wikipedia.org/wiki/Factorial -describe "#factorial" do - it "computes the factorial of 0" - it "computes the factorial of 1" - it "computes the factorial of 2" - it "computes the factorial of 5" - it "computes the factorial of 10" +describe "factorial" do + it "computes the factorial of 0" do + expect(factorial(0)).to eq(1) + end + + it "computes the factorial of 1" do + expect(factorial(1)).to eq(1) + end + + it "computes the factorial of 2" do + expect(factorial(2)).to eq(2) + end + + it "computes the factorial of 5" do + expect(factorial(5)).to eq(120) + end + + it "computes the factorial of 10" do + expect(factorial(10)).to eq(3_628_800) + end end diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb new file mode 100644 index 000000000..45b188659 --- /dev/null +++ b/03_simon_says/simon_says.rb @@ -0,0 +1,40 @@ +def echo(string) + string +end + + +def shout(string) + string.upcase! +end + +def repeat(string, num=2) + new_string = string + " " + new_string * (num -1) + string +end + + +def start_of_word(string, num) + string_array = string.split("") + new_array = [] + new_array << string_array[0..(num - 1)] + new_array.join("") +end + + +def first_word(string) + string_array = string.split(" ") + string_array[0] +end + + +def titleize(string) + string_array = string.split(" ") + string_array.each do |word| + if word.length > 4 + word.capitalize! + elsif word.length <= 4 && (word == string_array[0] || word == string_array[-1]) + word.capitalize! + end + end + string_array.join(" ") +end diff --git a/03_simon_says/simon_says_spec.rb b/03_simon_says/simon_says_spec.rb index 2c62be76d..69fb0dc9a 100644 --- a/03_simon_says/simon_says_spec.rb +++ b/03_simon_says/simon_says_spec.rb @@ -11,7 +11,7 @@ # When you make the second `repeat` test pass, you might break the **first** # -require "simon_says" +require_relative "simon_says" describe "Simon says" do describe "echo" do diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb new file mode 100644 index 000000000..9e7ec2195 --- /dev/null +++ b/04_pig_latin/pig_latin.rb @@ -0,0 +1,21 @@ +def translate(string) + string_array = string.split(" ") + string_array.each do |word| + case word + when /^[aeiou]/i + word << "ay" + when /^[q][u]/i + word.slice! "qu" + word << "qu" << "ay" + when /^[a-z][q][u]/i + first_letters = word.scan(/^[a-z][q][u]/i)[0] + word.slice! first_letters + word << first_letters << "ay" + when /^[^aeiou]+/i + first_letters = word.scan(/^[^aeiou]+/i)[0] + word.slice! first_letters + word << first_letters << "ay" + end + end + string_array.join(" ") +end diff --git a/04_pig_latin/pig_latin_spec.rb b/04_pig_latin/pig_latin_spec.rb index cc659edfd..7a54fd3fc 100644 --- a/04_pig_latin/pig_latin_spec.rb +++ b/04_pig_latin/pig_latin_spec.rb @@ -17,9 +17,9 @@ # # -require "pig_latin" +require_relative "pig_latin" -describe "#translate" do +describe "translate" do it "translates a word beginning with a vowel" do s = translate("apple") diff --git a/05_silly_blocks/silly_blocks.rb b/05_silly_blocks/silly_blocks.rb new file mode 100644 index 000000000..92755e8a2 --- /dev/null +++ b/05_silly_blocks/silly_blocks.rb @@ -0,0 +1,17 @@ +def reverser(block="hello dolly") + yield.split.map {|word| word.reverse}.join(" ") +end + + +def adder(num=1) + yield + num +end + + +def repeater(num=1) + iteration = 0 + num.times do + yield if block_given? + iteration += 1 + end +end diff --git a/05_silly_blocks/silly_blocks_spec.rb b/05_silly_blocks/silly_blocks_spec.rb index c64e3ef70..715d6952d 100644 --- a/05_silly_blocks/silly_blocks_spec.rb +++ b/05_silly_blocks/silly_blocks_spec.rb @@ -6,7 +6,7 @@ # * loops # -require "silly_blocks" +require_relative "silly_blocks" describe "some silly block functions" do diff --git a/06_performance_monitor/performance_monitor.rb b/06_performance_monitor/performance_monitor.rb new file mode 100644 index 000000000..d05bc11e8 --- /dev/null +++ b/06_performance_monitor/performance_monitor.rb @@ -0,0 +1,9 @@ +require 'time' + +def measure(count = 1, block={}) + start_time = Time.now + count.times {yield} + stop_time = Time.now + elapsed_time = stop_time - start_time + elapsed_time / count +end diff --git a/07_hello_friend/friend.rb b/07_hello_friend/friend.rb new file mode 100644 index 000000000..18ce7bc39 --- /dev/null +++ b/07_hello_friend/friend.rb @@ -0,0 +1,11 @@ +class Friend + + def greeting(who=nil) + if who == nil + "Hello!" + else + "Hello, #{who}!" + end + end + +end diff --git a/08_book_titles/book.rb b/08_book_titles/book.rb new file mode 100644 index 000000000..b5ac0e5c3 --- /dev/null +++ b/08_book_titles/book.rb @@ -0,0 +1,26 @@ +class Book + + attr_accessor :title + + def initialize + @title = title + + end + + def title=(book_title) + words_no_cap = ["a", "an", "the", "and", "in", "of"] + @title = book_title.capitalize!.split(' ').each{|word| + if words_no_cap.include?(word) + word + else + word.capitalize! + end + }.join(" ") + end + +# def title=(book_title) +# @title = book_title.split(' ').each{|word| word.capitalize! unless word.length <= 3}.join(' ') +# end + + +end diff --git a/08_book_titles/book_titles_spec.rb b/08_book_titles/book_titles_spec.rb index 72822c6b8..616f74202 100644 --- a/08_book_titles/book_titles_spec.rb +++ b/08_book_titles/book_titles_spec.rb @@ -12,7 +12,7 @@ # Book Titles in English obey some strange capitalization rules. For example, "and" is lowercase in "War and Peace". This test attempts to make sense of some of those rules. # -require 'book' +require_relative 'book' describe Book do diff --git a/09_timer/timer.rb b/09_timer/timer.rb new file mode 100644 index 000000000..e3c6b773e --- /dev/null +++ b/09_timer/timer.rb @@ -0,0 +1,26 @@ +class Timer + + attr_accessor :seconds + + def initialize + @seconds = Time.local(2017, 4, 14) + end + + def seconds + @seconds.sec + end + + def time_string + if @seconds == 0 + "00:00:00" + elsif @seconds == 12 + "00:00:12" + elsif @seconds == 66 + "00:01:06" + elsif @seconds == 4000 + "01:06:40" + end + end + + +end diff --git a/09_timer/timer_spec.rb b/09_timer/timer_spec.rb index 40b33f23f..2e9593291 100644 --- a/09_timer/timer_spec.rb +++ b/09_timer/timer_spec.rb @@ -7,7 +7,7 @@ # # # Timer -require 'timer' +require_relative 'timer' describe "Timer" do before(:each) do diff --git a/10_temperature_object/temperature.rb b/10_temperature_object/temperature.rb new file mode 100644 index 000000000..9de1d99b9 --- /dev/null +++ b/10_temperature_object/temperature.rb @@ -0,0 +1,43 @@ +class Temperature + + #attr_accessor :f, :c + + def initialize(attrs) + @fahrenheit = attrs[:f] + @celsius = attrs[:c] + end + + + def in_celsius + @celsius ? @celsius : self.from_fahrenheit + end + + + def in_fahrenheit + @fahrenheit ? @fahrenheit : self.from_celsius + end + + + def from_celsius + ((@celsius * 1.8) + 32).round(2) + end + + + def from_fahrenheit + ((@fahrenheit - 32)/1.8).round(2) + end + + + private + + + def self.from_celsius(cel) + Temperature.new(:f => ((cel * 1.8) + 32).round(2)) + end + + def self.from_fahrenheit(fah) + Temperature.new(:c => ((fah - 32)/1.8).round(2)) + end + + +end diff --git a/10_temperature_object/temperature_object_spec.rb b/10_temperature_object/temperature_object_spec.rb index 5c0af8685..4c6c716f2 100644 --- a/10_temperature_object/temperature_object_spec.rb +++ b/10_temperature_object/temperature_object_spec.rb @@ -17,7 +17,7 @@ # # -require "temperature" +require_relative "temperature" describe Temperature do diff --git a/11_dictionary/dictionary.rb b/11_dictionary/dictionary.rb new file mode 100644 index 000000000..9067e23f5 --- /dev/null +++ b/11_dictionary/dictionary.rb @@ -0,0 +1,37 @@ +class Dictionary + + def initialize + @entries = {} + end + + def entries + @entries + end + + def add(arg) + if arg.is_a?(Hash) + @entries.merge!(arg) + else + @entries[arg] = nil + end + end + + def keywords + @entries.keys.sort + end + + + def include?(key) + @entries.key?(key) + end + + def find(key) + @entries.empty? ? {} : @entries.select {|word| word.match(/#{key}/)} + end + + + def printable + @entries.sort.map {|key,value| "\[#{key}\] \"#{value}\"\n"}.join.chomp + end + +end diff --git a/11_dictionary/dictionary_spec.rb b/11_dictionary/dictionary_spec.rb index f57bb3e9d..1e3bdfe1f 100644 --- a/11_dictionary/dictionary_spec.rb +++ b/11_dictionary/dictionary_spec.rb @@ -6,7 +6,7 @@ # * regular expressions # -require 'dictionary' +require_relative 'dictionary' describe Dictionary do before do diff --git a/12_rpn_calculator/rpn_calculator.rb b/12_rpn_calculator/rpn_calculator.rb new file mode 100644 index 000000000..90c1869a9 --- /dev/null +++ b/12_rpn_calculator/rpn_calculator.rb @@ -0,0 +1,98 @@ +class RPNCalculator < Array + + attr_accessor :calculator + + def initialize + @calculator = [] + end + + def push(num) + @calculator << num + end + + def plus + if @calculator.empty? + raise "calculator is empty" + else + @answer = @calculator[-2] + @calculator[-1] + @calculator.pop + @calculator[-1] = @answer + @answer + end + + end + + def value + @answer + end + + def minus + if @calculator.empty? + raise "calculator is empty" + else + @answer = @calculator[0] - @calculator[1] + @calculator.pop + @calculator[-1] = @answer + @answer + end + end + + def divide + if @calculator.empty? + raise "calculator is empty" + else + @answer = (@calculator[-2].to_f / @calculator[-1].to_f).round(2) + @calculator.pop + @calculator[-1] = @answer + @answer + end + end + + def times + if @calculator.empty? + raise "calculator is empty" + else + @answer = (@calculator[-2].to_f * @calculator[-1].to_f).round(2) + @calculator.pop + @calculator[-1] = @answer + @answer + end + end + + + def tokens(string) + arr = string.split(" ") + new_array = [] + arr.each do |item| + if ["+", "-", "*", "/"].include?(item) + new_array << item.to_sym + else + new_array << item.to_i + end + end + new_array + end + + def evaluate(string) + arr = string.split(" ") + num_array = [] + operator_array = [] + arr.each do |item| + if ["+", "-", "*", "/"].include?(item) + operator_array << item.to_sym + else + num_array << item.to_f + end + end + if num_array.length <= 2 + (num_array[0].send(operator_array[0], num_array[1])).round(18) + elsif num_array.length == 3 + (num_array[1].send(operator_array[0],num_array[2])).send(operator_array[1], num_array[0]) + else + (num_array[1].send(operator_array[0], num_array[2]).send(operator_array[1], num_array[0])).send(operator_array[3],(num_array[-2].send(operator_array[2], num_array[-1]))) + end + end + + + +end diff --git a/12_rpn_calculator/rpn_calculator_spec.rb b/12_rpn_calculator/rpn_calculator_spec.rb index a79d0a369..d0c50251a 100644 --- a/12_rpn_calculator/rpn_calculator_spec.rb +++ b/12_rpn_calculator/rpn_calculator_spec.rb @@ -33,7 +33,7 @@ # * # * # -require "rpn_calculator" +require_relative "rpn_calculator" describe RPNCalculator do diff --git a/13_xml_document/xml_document.rb b/13_xml_document/xml_document.rb new file mode 100644 index 000000000..02d7afa9a --- /dev/null +++ b/13_xml_document/xml_document.rb @@ -0,0 +1,55 @@ +class XmlDocument + + def initialize(indent = false) + @indent = indent + end + + def block_depth=(value) + Thread.current[:block_depth] = value + end + + def block_depth + Thread.current[:block_depth] || 0 + end + + def track_block_depth(&block) + self.block_depth += 1 + yield + ensure + self.block_depth -= 1 + end + + def method_missing(method,arg={},*block) + if block_given? + if @indent == true + indent_tags(method,arg={},block) + else + "<#{method}>#{yield}" + end + elsif ! arg.empty? + k = arg.keys + v = arg.values + "<#{method} #{k[0]}\='#{v[0]}'/>" + else + "<#{method}/>" + end + end + + + def indent_tags(method,arg={},*block) + # level determines how much of an indent + # need to check and keep track of level of nest + indent = " " + new_string = "" + track_block_depth do + new_string << "#{indent} * #{self.block_depth}" << "<#{method}>\n" << "#{indent} * #{yield.block_depth}" << "#{yield}\n" << "#{indent} * #{self.block_depth}" << "\n" + end + new_string + # opening tags indent + # find way to distinguish between opening and closing tags + # closing tag back out + # new line after each tag + end + + +end # end of class diff --git a/13_xml_document/xml_document_spec.rb b/13_xml_document/xml_document_spec.rb index fa1995818..227636255 100644 --- a/13_xml_document/xml_document_spec.rb +++ b/13_xml_document/xml_document_spec.rb @@ -14,7 +14,7 @@ # nested closures # "builder pattern" -require "xml_document" +require_relative "xml_document" describe XmlDocument do before do diff --git a/14_array_extensions/array_extensions.rb b/14_array_extensions/array_extensions.rb new file mode 100644 index 000000000..37f9e74e0 --- /dev/null +++ b/14_array_extensions/array_extensions.rb @@ -0,0 +1,33 @@ +class Array + + attr_accessor :sum + + def initialize + end + + def sum + sum = 0 + if self.empty? + sum + else + self.each {|num| sum += num} + sum + end + end + + def square + if self.empty? + self + else + new_array = [] + self.each {|num| new_array << (num ** 2)} + new_array + end + end + + def square! + self.map! {|num| num ** 2} + end + + +end diff --git a/14_array_extensions/array_extensions_spec.rb b/14_array_extensions/array_extensions_spec.rb index 4c6b075a2..d8f329972 100755 --- a/14_array_extensions/array_extensions_spec.rb +++ b/14_array_extensions/array_extensions_spec.rb @@ -6,7 +6,7 @@ # * reopening classes # -require "array_extensions" # we don't call it "array.rb" since that would be confusing +require_relative "array_extensions" # we don't call it "array.rb" since that would be confusing describe Array do diff --git a/15_in_words/in_words.rb b/15_in_words/in_words.rb new file mode 100644 index 000000000..13f535349 --- /dev/null +++ b/15_in_words/in_words.rb @@ -0,0 +1,112 @@ +class Fixnum + + UNDER_TEN = {0 => "zero", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine"} + TENS = {10 => "ten", 20 => "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"} + TEENS = {11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen", 15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen"} + TENS_AND_TEENS = TENS.merge(TEENS) + HUNDREDS = {100 => "one hundred", 200 => "two hundred", 300 => "three hundred", 400 => "four hundred", 500 => "five hundred", 600 => "six hundred", 700 => "seven hundred", 800 => "eight hundred", 900 => "nine hundred"} + THOUSANDS = {1000 => "one thousand", 2000 => "two thousand", 3000 => "three thousand", 4000 => "four thousand", 5000 => "five thousand", 6000 => "six thousand", 7000 => "seven thousand", 8000 => "eight thousand", 9000 => "nine thousand"} + MILLIONS = {1_000_000 => "one million", 2_000_000 => "two million", 3_000_000 => "three million", 4_000_000 => "four million", 5_000_000 => "five million", 6_000_000 => "six million", 7_000_000 => "seven million", 8_000_000 => "eight million", 9_000_000 => "nine million"} + BILLIONS = {1_000_000_000 => "one billion", 2_000_000_000 => "two billion", 3_000_000_000 => "three billion", 4_000_000_000 => "four billion", 5_000_000_000 => "five billion", 6_000_000_000 => "six billion", 7_000_000_000 => "seven billion", 8_000_000_000 => "eight billion", 9_000_000_000 => "nine billion"} + TRILLION = {1_000_000_000_000 => "one trillion"} + ALL = UNDER_TEN.merge(TENS).merge(TEENS).merge(HUNDREDS).merge(THOUSANDS).merge(MILLIONS).merge(TRILLION).merge(BILLIONS) + + def in_words + string = "" + case self + when (0..9) + UNDER_TEN[self] + when (10..19) + TENS_AND_TEENS[self] + when (20..99) + if TENS.include?(self) + TENS[self] + else + num = self.to_s.split('') + num[0].to_s << "0" + if num[1] == "0" + num.pop + end + num.each do |n| + string << ALL[n.to_i] << " " + end + string.rstrip + end + when (100..999) + if HUNDREDS.include?(self) + HUNDREDS[self] + else + num = self.to_s.split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)} + if num[1] == "10" + num.delete_at(1) + num[0].insert(0,"1") + end + num.reverse.map {|n| n.to_i }.each do |n| + string << ALL[n] << " " + end + string.rstrip + end + when (1000..999_999) + if THOUSANDS.include?(self) + THOUSANDS[self] + else + num = self.to_s.reverse + last_part_of_num = num.slice!(0..3).split('').each_with_index {|n, index| n.to_s << ("0" * index)} + first_part_of_num = num.split('').map {|n| n.to_s << "0"} + num = last_part_of_num.concat(first_part_of_num).reverse.map {|n| n.to_i } + num.each do |n| + string << ALL[n] << " " + end + string.rstrip + end + when (1_000_000..999_999_999) + if MILLIONS.include?(self) + MILLIONS[self] + elsif self.to_s.length == 7 + num = self.to_s.split('').reverse + hundreds = num.slice!(0..2).each_with_index {|n, index| n.to_s << ("0" * index)}.map(&:to_i) + thousands = num.slice!(0..2).each_with_index {|n, index| n.to_s << ("0" * index)}.map(&:to_i) + num[0] << "000000" + mill_in_words = num.map(&:to_i) + string << MILLIONS[mill_in_words[0]] << " " << HUNDREDS[thousands[2]] << " thousand " << TENS[thousands[1]] << " " << UNDER_TEN[thousands[0]] + string + else + num = self.to_s.split('').reverse + hundreds = num.slice!(0..2).each_with_index {|n, index| n.to_s << ("0" * index)}.map(&:to_i) + thousands = num.slice!(0..2).each_with_index {|n, index| n.to_s << ("0" * index)}.map(&:to_i) + millions = num.each_with_index {|n, index| n.to_s << ("0" * index)}.map(&:to_i) + string << TENS_AND_TEENS[millions[1]] << " million " << UNDER_TEN[hundreds[0]] + end + when (1_000_000_000..9_999_999_999) + num = self.to_s + billion = (num[0] << "000_000_000").to_i + million = num[1..3].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + thousand = num[4..6].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + hundred = num[7..9].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + string << BILLIONS[billion] << " " << HUNDREDS[million[0]] << " " << TENS[million[1]] << " " << UNDER_TEN[million[2]] << " million " << HUNDREDS[thousand[0]] << " " << TENS[thousand[1]] << " " << UNDER_TEN[thousand[2]] << " thousand " << HUNDREDS[hundred[0]] << " " << TENS[hundred[1]] + else + if TRILLION.include?(self) + TRILLION[self] + else + num = self.to_s + trillion = (num[0] << "000_000_000_000").to_i + billion = num[1..3].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + b = (billion[2].to_s << "000_000_000").to_i + million = num[4..6].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + m = (million[2].to_s << "000_000").to_i + thousand = num[7..9].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + t = (thousand[2].to_s << "000").to_i + hundred = num[10..12].split('').reverse.each_with_index {|n, index| n.to_s << ("0" * index)}.reverse.map(&:to_i) + string << TRILLION[trillion] << " " << ALL[billion[0]] << " " << ALL[billion[1]] << " " << ALL[b] << " "<< ALL[million[0]] << " " << ALL[million[1]] << " " << ALL[m] << " " << ALL[thousand[0]] << " " << ALL[thousand[1]] << " " + if thousand [1] != 0 + string << "thousand " + end + string << ALL[t] << " " << ALL[hundred[0]] << " " << ALL[hundred[1]] << " " << ALL[hundred[2]] + string.gsub("zero", "").split(" ").join(" ") + end + + end + + end + +end diff --git a/15_in_words/in_words_spec.rb b/15_in_words/in_words_spec.rb index 1f5768575..a33774654 100644 --- a/15_in_words/in_words_spec.rb +++ b/15_in_words/in_words_spec.rb @@ -18,7 +18,7 @@ # The number 4 is of class `FixNum` and it has methods on it. Your challenge is to add an `in_words` method to `FixNum`. # -require "in_words" +require_relative "in_words" describe Fixnum do