鉴于方法:
def foo(a,b=5,c=1)
return a+(b*c)
end
Run Code Online (Sandbox Code Playgroud)
跑步foo(1)应该回来6.但是,你会怎么做这样的事情:foo(1,DEFAULT,2).我需要更改第三个值,但使用默认的第二个值.
你会怎么做?(注意:我不能只改变变量的顺序,因为它们是来自gem的方法的参数)
我正在运行Windows + Ruby2.3,并弄乱了该tk库。我试图使其绘制不同颜色的矩形网格,但是每当我尝试向画布添加形状时,脚本都会崩溃。这是简化的代码版本:
require 'tk'
require 'tkextlib/tile'
root = TkRoot.new
content = Tk::Tile::Frame.new(root)
canvas = TkCanvas.new(content)
line = TkcLine.new( canvas, 0, 0, 10, 10, :fill => 'red' )
Tk.mainloop
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,出现以下错误+回溯:
C:/Ruby23/lib/ruby/2.3.0/tk/itemconfig.rb:115:in `hash_kv': wrong argument type nil (expected Array) (TypeError)
from C:/Ruby23/lib/ruby/2.3.0/tk/itemconfig.rb:115:in `itemconfig_hash_kv'
from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:722:in `_parse_create_args'
from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:735:in `create'
from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:758:in `create_self'
from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:751:in `initialize'
from C:/nopathforyou.rb:9:in `new'
from C:/nopathforyou.rb:9:in `<main>'
Run Code Online (Sandbox Code Playgroud)
有人知道该怎么办吗?提前致谢。