I did a quick spike to see if Kernel.as could provide a solution.
protected
"James "
end
end
protected
"Lynn "
end
end
attr_accessor :person
include James
include Lynn
as(person).name
end
"Holbrook"
end
end
member = FamilyMember.new
member.person = James
member.name # => "James Holbrook"
member.person = Lynn
member.name # => "Lynn Holbrook"
member.first_name rescue "first_name is not defined" # => "first_name is not defined"
There's a few interesting things about this solution. I can change the behavior at runtime by changing the person attribute. Also, the behavior is actually on the class instead of living on an independent state object that delegates back to the class. Lastly, each method is protected so they must be accessed via the delegations, and an error will occur if they are accessed directly.