This file contains 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 Die | |
attr_accessor :faces | |
def initialize(faces) | |
@faces = faces | |
end | |
def sides | |
@faces | |
end | |
def roll | |
self.rand(1..6) |
This file contains 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 Die | |
attr_accessor :faces | |
def initialize(faces) | |
@faces = faces | |
end | |
def sides | |
@faces | |
end | |
def roll | |
(1..@faces).to_a.sample |
This file contains 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 smiley(hash) | |
myhash = {"happy" => ":)"} | |
hash.each do |key, value| | |
myhash[value] | |
end | |
end |
This file contains 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 smiley(hash) | |
myhash = {"happy" => ":)"} | |
hash.each do |key, value| | |
end | |
myhash["happy"] | |
end |
This file contains 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> |
This file contains 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 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 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 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 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"} | |
OlderNewer