This file contains hidden or 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
| def factorial(number) | |
| product = 1 | |
| if number != 0 | |
| (1..number).each do |operand| | |
| product *= operand | |
| end | |
| end | |
| product | |
| end |
This file contains hidden or 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
| module InWords | |
| def in_words(*word_generated) | |
| num_array = self.to_s.split("") | |
| num_array.collect! { |x| x.to_i } | |
| hundreds_place = "" | |
| number_block = num_array.pop(num_array.length > 3 ? 3 : num_array.length) | |
| word_generated << word_generator(number_block, hundreds_place) | |
| #recursive call on in_words | |
| if num_array.empty? |
This file contains hidden or 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
| module InWords | |
| def in_words | |
| num_array = self.to_s.split("") | |
| num_array.collect! { |x| x.to_i } | |
| hundreds = "" | |
| if num_array.length == 3 | |
| hundreds = "#{numbers_hash[num_array.first]} hundred " | |
| end |
This file contains hidden or 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
| class Dictionary | |
| def initialize | |
| @dictionary_entries = {} | |
| end | |
| def entries | |
| @dictionary_entries | |
| end |
This file contains hidden or 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
| class RPNCalculator | |
| def initialize | |
| @calc_array= [] | |
| end | |
| def push(num) | |
| @calc_array << num | |
| end | |
| def plus | |
| @calc_array.reverse.each do |number| |
This file contains hidden or 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
| class Book | |
| def initialize | |
| end | |
| def title | |
| @book_title | |
| end | |
| def title=(book_title) |
This file contains hidden or 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
| class Dictionary | |
| def initialize(entries = {}) | |
| @entries = entries | |
| end | |
| def add(new_entry) | |
| new_entry = { new_entry => nil } if new_entry.is_a?(String) | |
| @entries.merge! new_entry | |
| end |
This file contains hidden or 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
| class Array | |
| def new_count | |
| counter = 0 | |
| (0..self.length).each do |n, index| | |
| if yield (n) | |
| counter += 1 | |
| end | |
| end | |
| counter | |
| end |
This file contains hidden or 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
| class Array | |
| def new_collect | |
| self.each_with_index do |n, i| | |
| self[i] = yield(n) | |
| end | |
| end | |
| end |
This file contains hidden or 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
| module Enumerable | |
| def new_inject(*initial_value) | |
| loaded_array = [] | |
| #change to Ranges to Array | |
| if self.class == Range | |
| loaded_array = self.to_a | |
| else | |
| loaded_array = self | |
| end |
OlderNewer