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
| 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 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
| 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
| module InWords | |
| def in_words | |
| ones = { 0 => "zero", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", | |
| 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine"} | |
| teens = { 11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen", | |
| 15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", | |
| 19 => "nineteen"} | |
| tens = { 0 => "", 1 => "ten", 2 => "twenty", 3 => "thirty", 4 => "forty", | |
| 5 => "fifty", 6 => "sixty", 7 => "seventy", 8 => "eighty", 9 => "ninety"} | |
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 first_character(word) <--- the argument for the method is accessable inside the method. | |
| word = "#{word}" <--- this line is redundant. Try running your code without this line. | |
| word[0] | |
| 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 PostsController < ActionController::Base | |
| def create | |
| Post.create(post_params) | |
| end | |
| def update | |
| Post.find(params[:id]).update_attributes!(post_params) | |
| end | |
| private |
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
| 1.9.3p125 :001 > u = User.first | |
| User Load (0.6ms) SELECT "users".* FROM "users" LIMIT 1 | |
| => #<User id: 1, name: "aaron", age: nil, email: nil, username: nil, password: nil, created_at: "2012-10-30 01:39:34", updated_at: "2012-10-30 01:39:34"> | |
| 1.9.3p125 :002 > u.bumps | |
| Bump Load (0.6ms) SELECT "bumps".* FROM "bumps" WHERE "bumps"."user_id" = 1 | |
| => [#<Bump id: 1, post_id: 1, user_id: 1, bumped_id: nil, created_at: "2012-10-30 01:53:13", updated_at: "2012-10-30 01:53:13">] | |
| 1.9.3p125 :003 > p = Post.first | |
| Post Load (0.5ms) SELECT "posts".* FROM "posts" LIMIT 1 | |
| => #<Post id: 1, body: nil, reading_id: nil, user_id: 1, created_at: "2012-10-30 01:46:34", updated_at: "2012-10-30 01:46:34"> | |
| 1.9.3p125 :004 > p.bumps |
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 create | |
| @user = User.new(params[:user]) | |
| if @user.save | |
| redirect_to new_photo_path #NEED TO FIX THIS AND CREATE EDIT METHODS | |
| else | |
| flash[:error] = "Error" | |
| redirect_to new_user_path | |
| 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
| <h1>Users#new</h1> | |
| <p>Find me in app/views/users/new.html.erb</p> | |
| <% flash.each do |key, value| %> | |
| <div class="alert fadeout alert-<%= key %>"><%= value %></div> | |
| </div> | |
| <% end %> | |
| <br> | |
| <span>You appear to be a new user. Please sign up below.</span><br> |