Last active
April 11, 2019 14:35
-
-
Save Kutomore/49e9bd25570c60ca6d3db81ab18d8218 to your computer and use it in GitHub Desktop.
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 User | |
def born_on | |
Date.new(1989, 09, 10) | |
end | |
end | |
class UserDecorator < SimpleDelegator | |
def birth_year | |
born_on.year | |
end | |
end | |
decorated_user = UserDecorator.new(User.new) | |
decorated_user.birth_year #=> 1989 | |
decorated_user.__getobj__ #=> #<User: ...> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment