Skip to content

Instantly share code, notes, and snippets.

@robhanlon22
Created August 26, 2011 00:55
Show Gist options
  • Save robhanlon22/1172428 to your computer and use it in GitHub Desktop.
Save robhanlon22/1172428 to your computer and use it in GitHub Desktop.
Rails delegate example
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