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
puts "What is your favorite number?" | |
favenum = gets.chomp | |
# Using Interpolation | |
puts "Well that looks great, but wouldn't #{favenum.to_i + 1} be better?" | |
# Using Concatenation | |
puts "Well that looks great, but wouldn't " + (favenum.to_i + 1).to_s + "be better?" |
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
line_width = 25 | |
begin | |
puts 'Table of Contents'.center(line_width) | |
puts 'Chapter 1: Intro'.ljust(line_width) + 'page 1'.rjust(line_width) | |
puts 'Chapter 2: Numbers'.ljust(line_width) + 'page 9'.rjust(line_width) | |
puts 'Chapter 3: Letters'.ljust(line_width) + 'page 13'.rjust(line_width) | |
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
counter = 10 | |
while counter > 0 | |
# Repeat what's in here as long as it's TRUE that the counter is greater than zero | |
puts "The counter is #{counter}" | |
counter = counter - 1 | |
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
N = number of models | |
D = developer days/model = I'd approximate 3 | |
C = complexity factor = 0.5 (ie, implementing 2 models is 3x as complex as one model) | |
M = number of views / model = 4 (on average) | |
E = developer days/view = I'd approximate 2 (given time for revisions, etc) | |
x = "Complexity" = C * (N ^ 2) | |
y = "Code" = D * N | |
z = "User Interface" = N * M * E | |
total = x + y + z |
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
begin | |
beer = 3 | |
while beer > 1 | |
# Repeat what's in here as long as it's TRUE that the counter is greater than zero | |
puts "#{beer} bottles of beer on the wall, #{beer} bottles of beer! Take one down and pass it around," | |
beer = beer - 1 | |
if beer > 1 | |
puts "#{beer} bottles of beer on the wall." | |
else | |
puts "#{beer} bottle of beer on the wall." |
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><%= pluralize @articles.count, "Article" %></h1> | |
<%= link_to "Add", new_article_path, :class => "new_article" %> | |
<ul id="articles"> | |
<% @articles.each do |article| %> | |
<li><%= link_to article.title, article_path(article) %></li> | |
<% end %> | |
</ul> |
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
require "rubygems" | |
require "fastercsv" | |
class SalAttend | |
attr_accessor :file | |
attr_accessor :headers | |
# Added the parameter here... | |
def initialize(filename) | |
puts "JSAttend Initialized" |
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 ApplicationController < ActionController::Base | |
protect_from_forgery | |
before_filter :lookup, :only => [:show, :destroy, :edit, :update] | |
def lookup | |
class_name = params[:controller].singularize | |
klass = class_name.camelize.constantize | |
self.instance_variable_set "@" + class_name, klass.find(params[:id]) | |
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
# Run this from the command line, not the console: | |
rails generate migration add_body_to_articles body:string | |
rake db:migrate |
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
JSBlogger::Application.routes.draw do | |
resources :articles | |
resources :comments | |
match '/' => 'articles#index' | |
end |