Skip to content

Instantly share code, notes, and snippets.

@amite
Created December 27, 2012 01:59
Show Gist options
  • Save amite/4384799 to your computer and use it in GitHub Desktop.
Save amite/4384799 to your computer and use it in GitHub Desktop.
require 'forwardable'
class User
extend Forwardable
attr_accessor :view_delegate_class, :first_name, :last_name
def_delegators :view_delegate, :full_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def view_delegate
(@view_delegate_class || UserViewDelegate).new(self)
end
end
class UserViewDelegate
def initialize(user)
@user = user
end
def full_name
"#{first_name} #{last_name}"
end
def method_missing(name, *args)
@user.send(name, *args)
end
end
abhay = User.new('abhay', 'tandon')
puts abhay.full_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment