Skip to content

Instantly share code, notes, and snippets.

View erubboli's full-sized avatar

Enrico Rubboli erubboli

View GitHub Profile
class PizzaFactory
def create_pizza( type )
case type
when :ham_mushroom
HamMushroomPizza.new
when :deluxe
DeluxePizza.new
when :hawaiian
HawaiianPizza.new
else
class Base
def self.mysql_connector(config)
#...
end
def self.oracle_connector(config)
#...
end
end
class PizzaFactory {
public enum PizzaType {
HamMushroom,
Deluxe,
Hawaiian
}
public static Pizza createPizza(PizzaType pizzaType) {
switch (pizzaType) {
class Currency < ActiveRecord::Base
end
class CurrencyObserver < ActiveRecord::Observer
observe :currency
def after_update(currency)
puts "new rate for #{currency.symbol} : #{currency.rate}"
end
end
require "observer"
class Currency
include Observable
def initialize(symbol,rate)
@rate = rate
@symbol = symbol
end
#test
class Logger
def warning( msg )
#...
end
end
#production
class SingletonLogger < Logger
include Singleton
class Logger
include Singleton
def warning( msg )
#...
end
end
a = Logger.instance
function ss {
if [ -e script/rails ]; then
script/rails server $@
else
script/server $@
fi
}
function sc {
if [ -e script/rails ]; then
script/rails console $@
class Poker
def initialize(game)
@game = game
end
def evaluate_cards
#...
@game.primitive_operation
#...
end
class Poker
def evaluate_cards
primitive_operation1
primitive_operation2
end
def primitive_operation1
raise "template method called!"
end