惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
V
V2EX
T
The Blog of Author Tim Ferriss
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
Vercel News
Vercel News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
美团技术团队
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks

博客园 - 阿飞外传

简单rails开发环境 关于MDA的长期等待 Is MOF the kernel language of MDA langs family graduated 语言内实例表示机制 类型信息隐藏 MOF自描述 图模式-续 符号软件工程(SSE) next MDA? Algebra operator declaration 's UML profile 应用元建模读书笔记 再谈实例化和图转换 EclipseUML2.0::Class的接口 主题与模型 MDA轮廓 UML::Element的代数规范 UML::InstanceValue是元类吗 MDA is a big reflection i need a job CGN的IP之父访谈的两句话 A sample of writing a loop in Action Semantic codes
ruby-core
阿飞外传 · 2006-09-21 · via 博客园 - 阿飞外传

包中的是ruby的核心类(算是M2+M3级)
外面的User是M1级。 虚线是instance_of关系
具有金穗带构架,Object.instance_of?(Class) = true, Class.ancestors.include?(Object) = true

不是很明白,中间杀出个程咬金:Module

总体原则是,核心类簇中继承链中的叶类作为实例化关系的祖先, 即Class

一些特征:
1)特定于某对象的方法(单例类实例的方法)
  str = "sdfsdf"
  def str.foo
    puts "a per object method"
  end

2)DSL特征,在Module类中增加方法,以便用户类在定义时调用。

class Module
  @@doc = {}
  def doc(str)
    @@doc[self.name] = str
  end
  def Moduel.doc(aClass)
    aClass = aClass.name if aClass.class <= Module
    @@doc[aClass]
  end
end

class User
  doc "here is the doc for user"
end
 
3)条件定义

def foo
  if $DEBUG
    def foo
      puts "debug version"
    end
   else
  end
end 

4)匿名类

class User
   @class_val = 123
   class <<self
     def aClassMethod
       puts @class_val
     end
   end
end