Created
August 26, 2011 00:55
-
-
Save robhanlon22/1172428 to your computer and use it in GitHub Desktop.
Rails delegate example
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 Example | |
attr_reader :var | |
delegate :del, :to => :instance_var | |
alias_method :alias, :del | |
end | |
e = Example.new | |
e.del # calls e.var.del | |
e.alias # calls e.del, which calls e.var.del | |
# I had used alias_method to make the method name look better, | |
# but it just increased indirection unnecessarily. Hence, | |
# removing the alias_method call made things simpler but | |
# significantly less cute. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment