`
xhjay
  • 浏览: 11304 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

Ruby-使用动态参数生成类

阅读更多
利用ruby如何使用参数动态生成一个类,及其中的方法使用。如何做到? 以下是我的解决办法,请各位
class_name = "A"  
method_name = "test"  
code = "class #{class_name}  
  def #{method_name}  
     puts 'haha'  
  end  
end"  
  
eval(code)   
  
a = A.new  
a.test  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics