In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article to share with you is about Ruby metaprogramming code is what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some gains, not much to say, follow Xiaobian to see it.
1.Kernel#eval
2.0.0p247 :428 > array = ['10','20'] => ["10", "20"] 2.0.0p247 :429 > element = '30' => "30" 2.0.0p247 :430 > eval('array ["a", "b", "c\n"] 2.0.0p247 :424 > x = 'abc' => "abc" 2.0.0p247 :425 > array.instance_eval "self[1] = x" => "abc" 2.0.0p247 :426 > array => ["a", "abc", "c\n"] 2.0.0p247 :427 >2.0.0p247 :450 > def explore_array(method,*arg)2.0.0p247 :451?> ['a','b','c'].send(method, *arg)2.0.0p247 :452?> end => nil 2.0.0p247 :453 > explore_array(:size) => 3 2.0.0p247 :454 >
2. hook function inherited (more such as module included,method_added,method_removed,method_undefined)
2.0.0p247 :463 > class String2.0.0p247 :464?> def self.inherited(subclass)2.0.0p247 :465?> puts "hook function"2.0.0p247 :466?> end2.0.0p247 :467?> end => nil 2.0.0p247 :468 > class MyString
< String;end钩子函数 =>nil 2.0.0p247 :469 > The above is what Ruby metaprogramming code is, Xiaobian believes that some knowledge points may be what we see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.