Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
require_relative "../lib/postal_service"
app = PostalService::Application.new do
match :genre, '\S+'
match :title, '.*'
subject(:match, "a {genre} story '{title}'") do
respond :subject => "No one would consider '#{params[:title]}' to be #{params[:genre]}"
end
require_relative "../lib/postal_service"
app = PostalService::Application.new do
match :genre, '\S+'
match :title, '.*'
match :email, '[\w\d\._-]+@[\w\d\._-]+' #not legit, I'm sure
subject(:match, "a {genre} story '{title}'") do
respond :subject => "No one would consider '#{params[:title]}' to be #{params[:genre]}"
end
require_relative "../lib/postal_service"
def load_list(name)
PostalService::MailingList.new("db/lists/libre-#{name}.store")
end
app = PostalService::Application.new do
match :list_id, "[^.]+"
class Blog
attr_reader :entries
attr_accessor :post_class
def initialize
@entries = []
end
def title
"Underwater Basketweaving"
class Blog
attr_reader :entries
attr_writer :post_maker
def initialize
@entries = []
end
def title
"Underwater Basketweaving"

Continued from an MU community post by Jaime Iniesta...

A W3CLove supporter will be a user that loves the service provided and is conscious that by making use of it, is making the server spend money. So, to keep the service alive, decides to support it with a monthly subscription.

What does the supporter get in return for this monthly fee, apart from feeling well about supporting a great service? We could impose a limitation on the available features, so only supporters would access them, but we don't want to follow a scarcity based model. We believe everyone, supporter or not, should be able to access the same features.

Instead, what I'm going to do is put a daily requests limit for everyone. This step is needed to keep the costs under control. Say, each user can make 10 site validations per day (numbers may vary). When you reach this limit, you're warned that you're requesting too much, so you can wait until tomorrow, or you c

Although classical inheritance is centered around the concept of code sharing via class-based hierarchies, modern object oriented programming languages provide many different mechanisms for code sharing. Ruby is no exception, providing four common ways to model inheritance-based relationships between objects

  • Classes provide a single-inheritance model similar to what is found in many other object oriented languages.

  • Modules provide a mechanism for modeling multiple inheritance which is easier to reason about than C++ style class inheritance but is more powerful than Java's interfaces.

  • Transparent delegation techniques make it possible for a subobject to dynamically forward messages to a superobject. This has similar effects to class/module based modeling on the subobject's contract, but preserves encapsulation between the objects.

  • Simple aggregation techniques make it possible to compose objects for the purpose of code sharing. This technique is most useful when the subobject is not meant to be a d

module Prawn
class Canvas
def initialize(document)
self.document = document
end
def method_missing(id, *a, &b)
document.send(id, *a, &b)
end
module Prawn
class Drawing
# should work as a drop-in, as all of this
# stuff will proxy to Document
include Prawn::Graphics
def initialize(document)
self.document = document
end
--- a/lib/newman/application.rb
+++ b/lib/newman/application.rb
@@ -233,9 +233,11 @@ module Newman
# this in a future Newman release.
def trigger_callbacks(controller)
+ match_data = {}
+
matched_callbacks = callbacks.select do |e|
filter = e[:filter]