Ruby on rails class笔记

class

class method 有别于 object method, 类似于java中的static method. 使用class method 不需要通过object。

3种定义class method的方法

class Functions

  def self.method1

    .... #第一种

  end

  class << self

    def method2

      ...#第二种

    end

  end

end

def Functions.method3

  ...#第三种,定义在class外部

end

ruby继承

ruby不可多继承(与C++区别)。隐式继承Object。显示继承的例子如下

class Dog

  ...

end

class Husky < Dog

  ...#定义同样的method将override

end

https://www.coursera.org/learn/ruby-on-rails-intro/home/welcome

猜你喜欢

转载自www.cnblogs.com/sockk/p/9695316.html