是否有可能拦截IRB输入?专门为class#Fixnum?
示例:
5
=> 5我需要做的是:(伪代码)
if IRB.input.is_a?(Fixnum)
some_method(IRB.input) # some_method(5)
end发布于 2015-02-05 05:57:49
看看这个文件。您可以找到Irb#eval_input方法并对它们进行修补:
# code before
@scanner.set_input(@context.io) do
signal_status(:IN_INPUT) do
if l = @context.io.gets
if l.match(/^\d+$/)
puts 'Integer found!'
end
print l if @context.verbose?
else
if @context.ignore_eof? and @context.io.readable_after_eof?
l = "\n"
if @context.verbose?
printf "Use \"exit\" to leave %s\n", @context.ap_name
end
else
print "\n"
end
end
l
end
end
# code afterIrb输出示例:
spark@think:~$ irb
2.1.5 :001 > 123
Integer found!
=> 123
2.1.5 :002 > "string"
=> "string" https://stackoverflow.com/questions/28336066
复制相似问题