🏳️🌈
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
from routes import * | |
from routes.util import url_for | |
m = Mapper() | |
m.resource('blog', 'blogs') | |
m.create_regs(['blogs']) | |
url_for('blog', id=2) # outputs '/blogs/2' | |
m.match('/blogs/2') # no match |
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 show | |
@note = Note.find(:where => 'id = 1') | |
rescue NotFound | |
redirect_to 'not_found', :status => 404 | |
rescue NoDatabase | |
logger.error('the db died again, shit') | |
redirect_to 'apology', :status => 500 | |
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
class Economy | |
def slowing? | |
self.value.today < self.value.yesterday | |
end | |
def slow_by(amount) | |
self.value -= amount | |
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
if foreigner = terrorist | |
imprison(foreigner) | |
else | |
release(foreigner) | |
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 show | |
@note = Note.find(:where => 'id = 1') | |
rescue NotFound | |
redirect_to 'not_found', :status => 404 | |
rescue NoDatabase | |
logger.error('the db died again, shit') | |
redirect_to 'apology', :status => 500 | |
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
class Foo(object): | |
def __init__(self,arg): | |
"""docstring for __init__""" | |
self.arg = arg | |
def dec(fn): | |
def wrapper(*args): | |
# args[0] is self. Lame | |
args[0].arg = 'not what you thought, huh?' | |
return fn(*args) |
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 Thingie | |
attr_accessor :element | |
def initialize(element) | |
self.element = Element.new(element) | |
# with a block | |
self.element.respond_to :click do | |
self.element.hide | |
... other stuff ... | |
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
class PhotoBox | |
attr_accessor :element, :images | |
def initialize(element) | |
# associate an element with this object | |
self.element = Element.new(element) | |
# give it a class | |
self.element.add_class('active') | |
# find subelemts and store them |
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
Customer < ActiveRecord::Base | |
before_destroy :log_deletion, :email_admin | |
private | |
def log_deletion | |
logger.info("customer id:#{self.id} was just deleted") | |
end | |
def email_admin | |
... |
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 Conference | |
has_many :attendees, :class_name => 'Person', :through => :attendance | |
def Conference.next_upcoming | |
self.find!(:first, :conditions => ['starting_at > ? and visibile = ?' Time.now, true]) | |
rescue RecordNotFound | |
self.most_recent | |
end | |
def most_recent |