Skip to content

Instantly share code, notes, and snippets.

@nthj
Created May 28, 2014 02:30
Show Gist options
  • Save nthj/a6e864a1c124213ee2b5 to your computer and use it in GitHub Desktop.
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
class Person < ActiveRecord::Base
end
class FullName < Struct.new(:surname, :given_name)
extend Sliceable
def to_s
"#{surname} #{given_name}"
end
end
module Sliceable
def for(record)
self.new(*record.slice(members))
end
end
<%= FullName.for(@person) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment