脚本宝典收集整理的这篇文章主要介绍了ruby开发的交互式程序例子,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
实现PRy,ronin,msf类似的终端下交互功能,这里主要用到了ripl gem:
1.能够调用定义的方法,如help
2.能够执行系统命令
3.能够类似irb/pry进行ruby语言解析
安装:
gem install ripl gem install ripl-shell_commands
示例
ripl这个gem,它也提供很多插件,如下是一个简单的终端下交互实现:
require 'ripl' require 'ripl/shell_commands' require 'ripl/color_result' require 'ripl/color_streams' require 'ripl/commands' require 'ripl/rocket' #设置输出颜色 Ripl.config[:color_streams_stdout] = :light_blue Ripl.config[:color_streams_stderr] = :light_red #定义提示符号 Ripl.config[:prompt] = lambda {"[#{Ripl.shell.line.to_s}] cmd> " } # define plugins, load files, etc... class Dodolook def help puts "xiaomi noops blog" end def name "wilbur" end end dodo = Dodolook.new verison = "1.0.3" Ripl.start :binding => dodo.instance_eval{ binding }
使用
在终端下运行程序后,出现[0] cmd>这样的提示,其中help、name、dodo这些变量/方法可以tab补全。
运行shell命令前加!,如:!DF
还有更多内部方法,如: history, list, jump…
以上是脚本宝典为你收集整理的ruby开发的交互式程序例子全部内容,希望文章能够帮你解决ruby开发的交互式程序例子所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。