Ruby的method_missing可以定义client调用不存在的方法时的行为
来源:互联网 发布:淘宝怎样提高排名 编辑:程序博客网 时间:2024/05/01 11:02
class X def method_missing( methodname, *args ) puts( "Class #{self.class} does not understand: #{methodname}( #{args.inspect} )" ) end endclass Y < X def aaa puts( "aaa method" ) end remove_method( :aaa )endclass Z < Y def method_missing( methodname, *args ) super puts( "Now creating method #{methodname}( )" ) self.class.send( :define_method, methodname, lambda{ |*args| puts( args.inspect) } ) end endob = X.newob.aaa( 1,2,3 )ob2 = Y.newob2.ccc( "hello world" )ob3 = Z.newob3.ddd( 1,2,3)ob3.ddd( 4,5,6 )=beginoutput:Class X does not understand: aaa( [1, 2, 3] )Class Y does not understand: ccc( ["hello world"] )Class Z does not understand: ddd( [1, 2, 3] )Now creating method ddd( )[4, 5, 6]=end
0 0
- Ruby的method_missing可以定义client调用不存在的方法时的行为
- method_missing,一个 Ruby 程序员的梦中情人
- 使用method_missing和respond_to?创建自己的动态方法
- 使用method_missing和respond_to?创建自己的动态方法
- java的调用方法行为
- ruby 方法之间的调用
- 在Service的内部定义一个start()方法,简化Client端的调用
- js中方法定义的时候没有定义参数,调用的时候可以传参吗?
- Ruby之旅(二) Ruby的基本语法以及对象的使用,方法的定义及调用,属性的定义及使用
- client和server相互调用的方法
- [Ruby] ruby中的拟态方法的调用中的小细节
- ruby调用执行shell命令的方法
- ruby shell 调用的六种方法
- Ruby中调用windows shell的方法
- 函数的调用行为
- Ruby的调用机制
- 定义组件行为的方式
- 修改window.external使JavaScript可以调用Delphi内定义的方法
- 我的知识记录
- 单例设计模式(C#) DoubleCheck
- Android之自定义Dialog
- C++堆还是栈上创建对象
- 史上最全的iOS面试题及答案
- Ruby的method_missing可以定义client调用不存在的方法时的行为
- ORA-12154: TNS: 无法解析指定的连接标识符
- poj 2485 Highways(Kruskal)
- bzoj 1021 dp
- [51nod 1292]字符串中的最大值V2
- Listen第二个参数的意义
- java基础学习之Layout
- android studio 传感器之加速度,临近,光线传感器
- GOTURN(Generic Object Tracking Using Regression Networks ECCV2016)