Skip to content

Instantly share code, notes, and snippets.

# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
@emmapersky
emmapersky / Kennel.rb
Created November 15, 2010 22:51
GDI Ruby (on Rails) lesson 2,slide 16
class Animal
attr_accessor :name, :color
def initialize(name, color)
@name = name
@color = color
end
def info
return "This is " + @name + " and she is " + @color
@emmapersky
emmapersky / AnimalWithInfo.rb
Created November 15, 2010 22:26
GDI Ruby (on Rails) class 2, slide 12
class Animal
attr_accessor :name, :color
def initialize(name, color)
@name = name
@color = color
end
def info
return "This is " + @name + " and she is " + @color
@emmapersky
emmapersky / Animal.rb
Created November 15, 2010 22:38
GDI Ruby (on Rails) class 2, slide 7
class Animal
attr_accessor :name, :color
end
an_anmial = Animal.new
another_animal = Animal.new
an_animal.name = "Fido"
another_animal.name = "Barney"
@emmapersky
emmapersky / AniamlWithProperties.rb
Created November 15, 2010 22:40
GDI Ruby (on Rails) class 2 slide 10
class Animal
attr_accessor :name, :color
def initialize(name, color)
@name = name
@color = color
end
end
fido = Animal.new("Fido", "Green")
@emmapersky
emmapersky / FarmAnimals.rb
Created November 15, 2010 23:00
GDI lesson 2 slide 18
class Animal
attr_accessor :name, :color, :age
def initialize(name, color, age)
@name = name
@color = color
@age = age
end
def info
@emmapersky
emmapersky / simple_app.rb
Created November 22, 2010 05:17
GDI Ruby Course, Lesson 3, Sample 1
require 'rubygems'
require 'sinatra'
get '/' do
"Hello, World!"
end
@emmapersky
emmapersky / gdi_animals.rb
Created November 22, 2010 05:48
GDI Ruby Lesson 3, simple animal
require 'rubygems'
require 'sinatra'
class Animal
attr_accessor :name
def initialize(name)
@name = name
end
def about
"#{@name} is urrrrrr?"
@emmapersky
emmapersky / simple_params.rb
Created November 22, 2010 05:19
GDI Ruby, Week 3, Sample 2
require 'rubygems'
require 'sinatra'
get '/say_hello/:name' do
"Hello #{params[:name]}"
end
@emmapersky
emmapersky / animal.erb
Created November 22, 2010 05:48
GDI Ruby Lesson 3, Simple Animal
<html>
<head>
<title>Animals!</title>
</head>
<body>
<% if @animal %>
<p>You create an animal - here is some info about it</p>
<p><%= @animal.about %></p>
<% end %>