后端开发2025年08月08日
ruby中的alias和alias_method都可以重命名一个方法,它们的区别如下: 1.alias是ruby的一个关键字,因此使用的时候是alias :newname :oldname alias_method是Module类的一个方法,因此使用的时候是alias_method :newname,:oldname,有一个逗号。 2.alias的参数可以...
后端开发2025年07月27日
class A def self.ask1 puts "the method of class" end def ask2 puts "the method of instance" end end #类的实例对象的方法,方法属于类所生成New出来的实例对象。 p a.methods.length p a.class...
后端开发2025年07月27日
我们知道顶级域,定义域的self是啥? puts self #main puts self.class #Object 我们知道当一个方法被调用的时候,如果没有对象接受,默认就是self,如: def tell_me_who puts self end tell_me_who #main 方法调用是这样的步骤,先查找当前对象的所在类的实例方法存在方法与否,...
后端开发2025年07月25日
class WIN32OLE def list_ole_methods method_names = ole_methods.collect {|m| m.name} puts method_names.sort.uniq end end WIN32OLE.new('Shell.Application').list_ole_methods 得到如下方法: ...