Tag: 定义

在别名实例方法时理解单例类

我正在使用Ruby 1.9.2和Ruby on Rails v3.2.2 gem。 我正在尝试以“正确的方式”学习元编程,此时我在RoR ActiveSupport::Concern模块提供的included do … end块中对实例方法进行别名: module MyModule extend ActiveSupport::Concern included do # Builds the instance method name. my_method_name = build_method_name.to_sym # => :my_method # Defines the :my_method instance method in the including class of MyModule. define_singleton_method(my_method_name) do |*args| # … end # Aliases the :my_method instance method in the […]

Ruby是脚本语言还是解释语言?

我刚刚注意到在Ruby的维基百科页面中,这种语言被定义为解释语言。 我明白可能在我的背景中缺少一些东西。 我一直都知道不需要编译器的解释语言和编译语言(需要在程序执行之前编译)之间的区别,但是脚本语言的特征是什么? Ruby是否可以作为脚本语言定义? 谢谢你,请原谅我