ruby 方法重载

作者: Ijavascript
发布时间:2015-07-13 11:31:33

class MyClass      def sayHello          return "hello from MyClass"      end      def sayGoodbye          return "Goodbye from MyClass"      end  end  class MyOtherClass < MyClass      def sayHello          return "Hello from MyOtherClass"      end      def sayGoodbye              return super << "and also from MyOtherClass"      end      def to_s          return "I am an instance of the #{self.class} class"      end  end

可以作为ruby语言的一大特性

标签: Ruby
来源:http://www.cnblogs.com/wangwenfei/p/ruby_over.html

推荐: