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
# How expensive is DCI in Ruby? | |
# http://news.ycombinator.com/item?id=4997498 | |
RUBY_VERSION # => "1.9.3" | |
RUBY_PATCHLEVEL # => 362 | |
RUBY_PLATFORM # => "x86_64-darwin12.2.0" | |
require 'benchmark' | |
require 'delegate' | |
require 'forwardable' |
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
@font-face { | |
font-family: SegoeUI; | |
src: | |
local("Segoe UI Light"), | |
url(//c.s-microsoft.com/static/fonts/segoe-ui/west-european/light/latest.woff2) format("woff2"), | |
url(//c.s-microsoft.com/static/fonts/segoe-ui/west-european/light/latest.woff) format("woff"), | |
url(//c.s-microsoft.com/static/fonts/segoe-ui/west-european/light/latest.ttf) format("truetype"); | |
font-weight: 100; | |
} |
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
# Under STI, find the top 10 accounts with the greatest balances | |
# with just one query. | |
top_accounts = Account.order(balance: :desc).limit(10) | |
# Under MTI, we need to query all accounts and sort them in memory: | |
top_corporate_accts = CorporateAccount.order(balance: :desc).limit(10) | |
top_sb_accts = SmallBusinessAccount.order(balance: :desc).limit(10) | |
top_personal_accts = PersonalAccount.order(balance: :desc).limit(10) |
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
# Suppose the AccountHolder parent class is used | |
# to simply have an association with an account so | |
# both corporations and people can have accounts. | |
class Account < ActiveRecord::Base | |
belongs_to :account_holder | |
end | |
class AccountHolder < ActiveRecord::Base | |
has_one :account |
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 < ActiveRecord::Base | |
def eat | |
end | |
end | |
class Bird < Animal | |
set_table_name "birds" | |
def fly | |
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 Animal < ActiveRecord::Base | |
def eat | |
end | |
end | |
class Bird < Animal | |
def fly | |
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
class Account < ActiveRecord::Base | |
def withdraw(amount) | |
# ... | |
end | |
def deposit(amount) | |
# ... | |
end | |
def close! |
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 Account < ActiveRecord::Base | |
def withdraw(amount) | |
# ... | |
end | |
def deposit(amount) | |
# ... | |
end | |
def close! |
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 'delegate' | |
class Account < Struct.new(:owner, :amount) | |
end | |
class MoneyTransferContext < Struct.new(:source, :destination) | |
def transfer(amount) | |
# applico i ruoli ai modelli "stupidi" | |
source_account = SourceRole.new(source) | |
destination_account = DestinationRole.new(destination) |
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
#!/usr/bin/env ruby | |
# Lean Architecture example in Ruby - without ContextAccessor | |
# In this example, the context passes the needed roles into each method it | |
# invokes, and so the roles have no reference back to the context. | |
# Model class with no external dependenices. Includes a simple find method | |
# to create and store instances given an id - for illustration purposes only. | |
class Account | |
attr_reader :account_id, :balance |
NewerOlder