Skip to content

Instantly share code, notes, and snippets.

View abrongersma's full-sized avatar

Aaron Brongersma abrongersma

View GitHub Profile
module InWords
require 'enumerator'
ONES= %w{one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen}.unshift("")
TENS = %w{twenty thirty forty fifty sixty seventy eighty ninety}.unshift("", "")
def in_words
r = ""
if self > 99
r = ONES[self/100] + " hundred " + (self%100).in_words
class RPNCalculator
@rpn
def initialize
@rpn = []
end
def push(num)
@rpn << num
end
class Fixnum
def fibonacci
if self < 2
self
else
(self - 1).fibonacci + (self - 2).fibonacci
end
end
end
class Integer
def fibonacci
a, b = 0, 1
return self if self < 2
2.upto(self) do
a, b = b, a+b
end
b
end
end
module InWords
def in_words
# recursion steps
# 573_917_408.in_words.should ==
# "(five hundred seventy three) million
# (nine hundred seventeen) thousand
# (four hundred)
# eight"
num = []
class Array
def new_count(&proc)
if proc
self.select(&proc).length
else
self.length
end
end
end
class Array
def new_count
col = []
self.each do |v|
if yield(v) == false
0
elsif yield(v) == true
col << true
col.length
else
class CoursesController < ApplicationController
# GET /courses
# GET /courses.json
def index
@courses = Course.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @courses }
end
class Package
attr_accessor :contents
attr_reader :from_location
attr_accessor :to_location
attr_reader :current_location
attr_reader :stops
def self.delivery_est(from, to)
if from == "San Francisco, CA" && to == "Chicago, IL"
2
class String
def title_case
stringarray = self.split
returnarray = []
articles = ["and", "of", "the", "a"]
stringarray.each do |a|
if stringarray.rindex(a) == 0
a.capitalize!
returnarray << a + " "