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
| 04a44d18d670a1cc327f128ed424dfc77273004670d59c2aeadbb2e247bd23473fce8244c797344df8c1115f05fcafbda3df2654f6e2bde22bbdf88dfbcc42ba1f |
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 | |
| attr_accessor :new_hash | |
| def initialize | |
| @hash = Hash.new | |
| end | |
| def new_entry(word, definition) | |
| @word = word | |
| @definition = definition |
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 Parcel | |
| attr_accessor :new_hash | |
| def initialize | |
| hash_empty = Hash.new | |
| @hash_empty = hash_empty | |
| end | |
| def new_box(length, width, height, weight) #inches and lbs | |
| @hash_empty = {"length" => length, "width" => width, "height" => height, "weight" => weight} |
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 Die | |
| attr_accessor :sides | |
| def initialize(number) | |
| @number = number | |
| end | |
| def roll | |
| rand(1..@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 | |
| attr_writer :title | |
| def initialize(title) | |
| @title = title | |
| end | |
| def new_book | |
| @title.to_s.split(/ /).map { |e| e.capitalize! }.join(" ") |
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 Integer | |
| def fibonacci | |
| if self.kind_of? Integer | |
| if self < 0 | |
| "Must be a positive number" | |
| else | |
| first_num = 0 | |
| second_num = 1 | |
| return self if (0..1).include? self | |
| (1..self).each do |counter| |
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 Fixnum | |
| def in_words | |
| one_nineteen = {"one" => "1", "two" => "2", "three" => "3", "four" => "4", "five" => "5", "six" => "6", "seven" => "7", "eight" => "8", "nine" => "9", "ten" => "10", "eleven" => "11", "twelve" => "12", "thirteen" => "13", "fourteen" => "14", "fifteen" => "15", "sixteen" => "16", "seventeen" => "17", "eighteen" => "18", "nineteen" => "19"} | |
| tens = {"twenty" => "2", "thirty" => "3", "fourty" => "4", "fifty" => "5", "sixty" => "6", "seventy" => "7", "eighty" => "8", "ninty" => "9"} | |
| big_nums = [" hundred ", " thousand ", " million ", " billion ", " trillion "] | |
| arrays = self.to_s.split(//) | |
| arrayi = arrays.map {|e| e.to_i} | |
| arrayi = arrayi.join |
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 Integer | |
| def fibonacci | |
| if self < 0 | |
| "Must be a positive number" | |
| elsif self == 0 | |
| 0 | |
| elsif self == 1 | |
| 1 | |
| else | |
| return (self - 1).fibonacci + (self - 2).fibonacci |
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(n) | |
| if n <= 1 | |
| "1" | |
| else (1..n).inject {|product, nb| product * nb } | |
| end | |
| end | |
| puts "'#{factorial(5)}' should equal '120'." |
NewerOlder