Created
May 28, 2014 02:30
-
-
Save nthj/a6e864a1c124213ee2b5 to your computer and use it in GitHub Desktop.
Mild refactoring of an example from "Rails Does Not Define Your Application Architecture" | http://www.naildrivin5.com/blog/2014/05/27/rails-does-not-define-your-application-architecture.html
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 Person < ActiveRecord::Base | |
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 FullName < Struct.new(:surname, :given_name) | |
extend Sliceable | |
def to_s | |
"#{surname} #{given_name}" | |
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
module Sliceable | |
def for(record) | |
self.new(*record.slice(members)) | |
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
<%= FullName.for(@person) %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment