---
title: "ruby 中环绕别名的小例子"
author: "bxp2012"
date: "2013-04-22T07:52:16Z"
tags: []
categories: ["编程语言"]
slug: "ruby"
draft: false
lastmod: "2013-04-22T07:52:56Z"
id: 1851202
url: "https://bxp2012.iteye.com/blog/1851202"
---

```java

class MyClass
   def greet
     puts "Hello!"
   end

   def greet_with_log
     puts "Calling method..."
     greet_without_log
     puts "...method called"
   end

   alias_method :greet_without_log, :greet
   alias_method :greet, :greet_with_log
end

MyClass.new.greet
MyClass.new.greet_without_log

```