Ruby [周末杂谈] Ruby 元编程之 E=mc2

daqing · August 24, 2014 · Last by daqing replied at August 24, 2014 · 2009 hits
E = mc2 = class << class << Class; self; end; self; end

周末无聊想到的,谁知道这段代码的含义吗?^_^

原文发表在我的博客上:http://mi.ngzhi.com/index.php/archives/23.html

E = mc2 = Class.singleton_class.singleton_class ……不知道有什么用,求指导

class << (class << Class; self; end)
  self
end

class << Class.singleton_class
  self
end

Class.singleton_class.singleton_class

前面的 E=mc2 质能等价公式就不知道啥意思了

E=mc2 就是定义了一个 mc2 的变量,又把这个变量赋值给了常量 E. class << class << Class; self; end; self; end 就是 Class.singleton_class.singleton_class

#2 楼 @ShiningRay 博客用 typecho 搭建的

You need to Sign in before reply, if you don't have an account, please Sign up first.