项目地址: https://github.com/xjz19901211/console
使用如下:
# my_console.rb
class MyConsole
include Console
define_cmd(:rand, "puts random number") do |max = 100|
puts rand(max.to_i)
end
end
MyConsole.new.start("my-console > ", "Use 'help' show all commands")
$ ruby my_console.rb
Use 'help' show all commands
my-console > help
help: show all commands
exit: exit console
rand: puts random number
my-console > rand
23
my-console > rand 10
4
my-console > rand 10100
2492
my-console > exit
$
非常简单快速就可以创建一个自己的简单 console Console 这模块也非常简单,50 多行代码,大家可以吐槽下,哈哈
是否有类似的 Gem 了?大家怎么看?