快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

我的ruby学习笔记

1.Moudle的方法
 undef_method(),会删除所以的方法,包括继承来的的方法。

创新互联公司总部坐落于成都市区,致力网站建设服务有网站设计制作、成都网站制作、网络营销策划、网页设计、网站维护、公众号搭建、微信小程序开发、软件开发等为企业提供一整套的信息化建设解决方案。创造真正意义上的网站建设,为互联网品牌在互动行销领域创造价值而不懈努力!

 remove_method(),只会删除接受者自己的方法。

2,单件方法

所谓的单件方法就算特定对象的特有方法,ruby中的类也是对象,所以类方法就是单件方法。

例如:

class A
  def method_a
    "this is a method"
  end
end
aa = A.new
bb = A.new
aa.method_a   #=>"this is a method"
bb.method_a   #=>"this is a method"
def aa.method_b
  "this is b method"
end
p aa.method_b   #=>"this is b method"
p bb.method_b   #=>"undefined method `method_b' for # (NoMethodError)"

这个挺容易理解,呵呵!

3.Moudle#class_evel()方法会在一个已存在的类的上下文中执行一个块

def add_method_to(a_class)
  a_class.class_eval do
    def m; "hello" ; end
end
end
add_method_to String
"abc".m  #=> "hello"

文章标题:我的ruby学习笔记
文章路径:http://6mz.cn/article/pcgoic.html

其他资讯