只是想知道,有没有办法在 Ruby 中使用宏来像 C 那样进行文本替换?
例如:
define ARGS 1,2
sum(ARGS) # returns 3
编辑:更具体地说,我的问题看起来更像:
@button1 = FXButton.new(self, "Button 1",:opts => BUTTONPROPERTIES,:width => width, :height => height)
@button2 = FXButton.new(self, "Button 2",:opts => BUTTONPROPERTIES,:width => width, :height => height)
@button3 = FXButton.new(self, "Button 3",:opts => BUTTONPROPERTIES,:width => width, :height => height)
理想情况下,我希望代码看起来像:
@button1 = FXButton.new(self, "Button 1", ALLBUTTONPROPERTIES)
@button2 = FXButton.new(self, "Button 2", ALLBUTTONPROPERTIES)
@button3 = FXButton.new(self, "Button 3", ALLBUTTONPROPERTIES)
请注意,如果我只是将它们设置为某个预定值,我的“宽度”和“高度”变量将无法正确传递给 FXButton 类的初始化。是否有某种代码替换可以解决这个问题?