Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created September 9, 2008 01:44
Show Gist options
  • Save dchelimsky/9597 to your computer and use it in GitHub Desktop.
Save dchelimsky/9597 to your computer and use it in GitHub Desktop.
class Foo
def self.capping_bar
alias_method :orig_bar, :bar
def bar; 'BAR'; end
yield
alias_method :bar, :orig_bar
end
def bar; 'bar'; end
end
f = Foo.new
Foo.capping_bar do
puts f.bar
end
puts f.bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment