Home Rubymotion在运行时的过程分析:1.message(rubymotionatrun Time:message)
Post
Cancel

Rubymotion在运行时的过程分析:1.message(rubymotionatrun Time:message)

refer to: http://www.rubymotion.com/developer-center/guides/runtime/#_ios_and_os_x

ruby 和 object c 都是受了smalltalk的极大影响。在语言构成上的也比较类型: 所有的类都是继承一个基本的类. single inheritance 等。

rubymotion 是使用了  object-c 的runtime 来实现了ruby语言,所以 可以直接调用 object c 的东东。

在 rubymotion中, ruby class 对应 object c class, ruby method 对应 object c method,  反之亦然。

我们可以比较下两者的代码:

Object C的代码:

[string drawAtPoint:point withFont:font];

Ruby: (RubyMotion) :

string.drawAtPoint(point, withFont:font)
# 或者
string.send(:'drawAtPoint:withFont:', point, font)
This post is licensed under CC BY 4.0 by the author.