Gem 一个简单的 Ruby console

xjz19901211 · May 17, 2015 · Last by chanshunli replied at May 20, 2015 · 2578 hits

项目地址: 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 了?大家怎么看?

说的是 irb、pry 之类吗

老谢!很久没有看你冒泡了,这是要定义自己的控制台 :plus1:

Unknow user #3 May 20, 2015

#2 楼 @kaka :plus1:

You need to Sign in before reply, if you don't have an account, please Sign up first.