如果我执行这个ruby代码:
def foo
100
end
p defined?(foo), foo
if false
foo = 200
end
p defined?(foo), foo
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
"method"
100
"local-variable"
nil
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么foo设置为nil不执行if后?这是预期的行为还是红宝石?
在JavaFx中,我想在动画结束后显示模态对话框.出于某种原因,在动画结束后执行的EventHandler中调用showAndWait不起作用.显示一个新窗口,但似乎内部没有任何内容.
此示例演示了此问题:
public void start(Stage primaryStage) {
Rectangle rect = RectangleBuilder.create().width(200).height(200).fill(Color.RED).build();
StackPane root = new StackPane();
root.getChildren().add(rect);
Timeline animation = new Timeline();
animation.getKeyFrames().addAll(
new KeyFrame(new Duration(1000),
new KeyValue(rect.widthProperty(), 100),
new KeyValue(rect.heightProperty(), 100)),
new KeyFrame(new Duration(2000),
new KeyValue(rect.widthProperty(), 300),
new KeyValue(rect.heightProperty(), 300))
);
animation.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
Stage stage = new Stage();
StackPane pane = new StackPane();
pane.getChildren().add(new Label("Hello world"));
stage.setScene(new Scene(pane, 100, 100));
stage.showAndWait();
}
});
animation.setCycleCount(1);
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene); …Run Code Online (Sandbox Code Playgroud)