This file contains hidden or 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 PizzaFactory { | |
| public enum PizzaType { | |
| HamMushroom, | |
| Deluxe, | |
| Hawaiian | |
| } | |
| public static Pizza createPizza(PizzaType pizzaType) { | |
| switch (pizzaType) { |
This file contains hidden or 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 Base | |
| def self.mysql_connector(config) | |
| #... | |
| end | |
| def self.oracle_connector(config) | |
| #... | |
| end | |
| end |
This file contains hidden or 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 PizzaFactory | |
| def create_pizza( type ) | |
| case type | |
| when :ham_mushroom | |
| HamMushroomPizza.new | |
| when :deluxe | |
| DeluxePizza.new | |
| when :hawaiian | |
| HawaiianPizza.new | |
| else |
This file contains hidden or 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
| module Leaf | |
| def land_size | |
| @land_size || 0 | |
| end | |
| end | |
| module Composite | |
| def append_child(child) | |
| @children << child | |
| end |
This file contains hidden or 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 City | |
| include Composite | |
| def initialize | |
| @children = [] | |
| end | |
| def count_children | |
| @children.lenght | |
| end |
This file contains hidden or 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
| module Leaf | |
| # ..omitted code.. | |
| def total_leafs | |
| 1 | |
| end | |
| end | |
| module Composite | |
| # .. omitted code.. | |
| def total_leafs |
This file contains hidden or 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 ClientsController < ApplicationController | |
| respond_to :html, :xml, :json | |
| # [..] removed code [..] | |
| # DELETE /clients/1 | |
| # DELETE /clients/1.xml | |
| def destroy | |
| @client = Client.find(params[:id]) |
This file contains hidden or 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
| erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ ruby -rubygems clean.rb | |
| erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ | |
| erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ gem list sinatra | |
| *** LOCAL GEMS *** | |
| sinatra (1.0) | |
| erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ gem list rack |
This file contains hidden or 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
| re = /(?<nome>[\S]+)\s(?<cognome>[\S]+)/ | |
| result = re.match "Enrico Rubboli" | |
| #=> #<MatchData "Enrico Rubboli" nome:"Enrico" cognome:"Rubboli"> | |
| result[:nome] | |
| #=> "Enrico" | |
| "Enrico Rubboli".sub re, '\k<cognome> \k<nome>' | |
| #=> "Rubboli Enrico" |
This file contains hidden or 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
| #Zero-width positive lookbehind | |
| "Enrico.Rubboli".match(/(?<=\.)(\w+)/) | |
| # => #<MatchData "Rubboli" 1:"Rubboli"> | |
| #Zero-width negative lookbehind | |
| "Enrico.Rubboli".match(/(?<!\.)(\w+)/) | |
| # => #<MatchData "Enrico" 1:"Enrico"> |