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
# 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) |
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 Animal | |
attr_accessor :name, :color | |
def initialize(name, color) | |
@name = name | |
@color = color | |
end | |
def info | |
return "This is " + @name + " and she is " + @color |
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 Animal | |
attr_accessor :name, :color | |
end | |
an_anmial = Animal.new | |
another_animal = Animal.new | |
an_animal.name = "Fido" | |
another_animal.name = "Barney" |
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 Animal | |
attr_accessor :name, :color | |
def initialize(name, color) | |
@name = name | |
@color = color | |
end | |
end | |
fido = Animal.new("Fido", "Green") |
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 Animal | |
attr_accessor :name, :color | |
def initialize(name, color) | |
@name = name | |
@color = color | |
end | |
def info | |
return "This is " + @name + " and she is " + @color |
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 Animal | |
attr_accessor :name, :color, :age | |
def initialize(name, color, age) | |
@name = name | |
@color = color | |
@age = age | |
end | |
def info |
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 'sinatra' | |
get '/' do | |
"Hello, World!" | |
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
require 'rubygems' | |
require 'sinatra' | |
get '/say_hello/:name' do | |
"Hello #{params[:name]}" | |
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
require 'rubygems' | |
require 'sinatra' | |
class Animal | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def about | |
"#{@name} is urrrrrr?" |
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
<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 %> | |
OlderNewer