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 | |
| 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 |
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 | |
| @rpn | |
| def initialize | |
| @rpn = [] | |
| end | |
| def push(num) | |
| @rpn << num | |
| 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 Fixnum | |
| def fibonacci | |
| if self < 2 | |
| self | |
| else | |
| (self - 1).fibonacci + (self - 2).fibonacci | |
| 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
| 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 |
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 | |
| # recursion steps | |
| # 573_917_408.in_words.should == | |
| # "(five hundred seventy three) million | |
| # (nine hundred seventeen) thousand | |
| # (four hundred) | |
| # eight" | |
| num = [] |
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(&proc) | |
| if proc | |
| self.select(&proc).length | |
| else | |
| self.length | |
| 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
| class Array | |
| def new_count | |
| col = [] | |
| self.each do |v| | |
| if yield(v) == false | |
| 0 | |
| elsif yield(v) == true | |
| col << true | |
| col.length | |
| else |
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 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 |
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 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 |
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 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 + " " |