Skip to content

Instantly share code, notes, and snippets.

View abrongersma's full-sized avatar

Aaron Brongersma abrongersma

View GitHub Profile
class Die
attr_accessor :faces
def initialize(faces)
@faces = faces
end
def sides
@faces
end
def roll
self.rand(1..6)
@abrongersma
abrongersma / gist:3614373
Created September 3, 2012 22:52
Die.class
class Die
attr_accessor :faces
def initialize(faces)
@faces = faces
end
def sides
@faces
end
def roll
(1..@faces).to_a.sample
def smiley(hash)
myhash = {"happy" => ":)"}
hash.each do |key, value|
myhash[value]
end
end
def smiley(hash)
myhash = {"happy" => ":)"}
hash.each do |key, value|
end
myhash["happy"]
end
@abrongersma
abrongersma / gist:3910339
Created October 18, 2012 07:53
New User view
<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>
@abrongersma
abrongersma / gist:3910345
Created October 18, 2012 07:56
User controller
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
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
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
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
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"}