Skip to content

Instantly share code, notes, and snippets.

View pzaich's full-sized avatar

Paul Zaich pzaich

View GitHub Profile
@pzaich
pzaich / gist:2920180
Created June 12, 2012 21:15
Injection methods
def factorial(number)
product = 1
if number != 0
(1..number).each do |operand|
product *= operand
end
end
product
end
@pzaich
pzaich / in_words_recursive
Created June 15, 2012 06:23
In_Words Recursive to Octillion
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?
@pzaich
pzaich / gist:2935097
Created June 15, 2012 06:59
In Words to 999
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
@pzaich
pzaich / gist:2938462
Created June 15, 2012 20:03
dictionary
class Dictionary
def initialize
@dictionary_entries = {}
end
def entries
@dictionary_entries
end
@pzaich
pzaich / gist:2939443
Created June 16, 2012 01:05
RPN calculator
class RPNCalculator
def initialize
@calc_array= []
end
def push(num)
@calc_array << num
end
def plus
@calc_array.reverse.each do |number|
@pzaich
pzaich / gist:2939444
Created June 16, 2012 01:05
Book Class
class Book
def initialize
end
def title
@book_title
end
def title=(book_title)
@pzaich
pzaich / gist:2939449
Created June 16, 2012 01:06
Dictionary Class
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
@pzaich
pzaich / gist:2946671
Created June 18, 2012 03:08
new_count method
class Array
def new_count
counter = 0
(0..self.length).each do |n, index|
if yield (n)
counter += 1
end
end
counter
end
@pzaich
pzaich / gist:2949634
Created June 18, 2012 17:42
new_collect
class Array
def new_collect
self.each_with_index do |n, i|
self[i] = yield(n)
end
end
end
@pzaich
pzaich / gist:2950739
Created June 18, 2012 21:10
new_inject method
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