我正在编写一个程序,它将为用户写日记,但是我遇到了一些麻烦...这是我的代码:
Shoes.app :title => "Diario", :width => 640, :height => 430 do
name = ask("Name")
n1 = ask("Yesterday's Date")
n2 = ask("Today's Date")
n3 = ask("Tommorow's Date")
w1 = ask("Yesterday's weather")
w2 = ask("Today's Weather")
w3 = ask("Tommorow's Weather")
a1 = ask("Yesterday's Activity")
a2 = ask("Today's Activity")
a3 = ask("Tommorow's Activity")
m = ask("Mood")
tw = ask("Today was...")
sn = ask("Special Notes")
@entry
para "Dear diary, The date is " + n2 + ". It is " + w2 + ". I will go to " + a2 + "."
para "Yesterday was " + n1 + ". It is " + w1 + ". I will go to " + a1 + "."
para "Tomorrow is " + n3 + ". It is " + w3 + ". I will go to " + a3 + "."
para "Today was " + tw + ". " + sn + "I am feeling " + m + "."
end
button "Save", :width => 85 do
file = ask_save_file
File.open(file, "w+") do |f|
@file.text = File.write(@entry.text)
end
end
- 但是当我运行代码时,我得到这个-
Error in <unknown> line 0 | 2017-03-15 20:44:14 -0400
undefined method `button' for main:Object
我知道这是一个错误,但无论如何请帮助我?谢谢,丹尼尔·
更新:问题解决了;我只需要将第一个"END"移动到末尾 - 它正在关闭应用程序块。但是,当我现在保存到文件时,它会保存为空白文件......有什么想法吗?
按钮在块 Shoes.app 之外
require 'shoes'
Shoes.app :title => "Diario", :width => 640, :height => 430 do
name = ask("Name")
n1 = ask("Yesterday's Date")
n2 = ask("Today's Date")
n3 = ask("Tommorow's Date")
w1 = ask("Yesterday's weather")
w2 = ask("Today's Weather")
w3 = ask("Tommorow's Weather")
a1 = ask("Yesterday's Activity")
a2 = ask("Today's Activity")
a3 = ask("Tommorow's Activity")
m = ask("Mood")
tw = ask("Today was...")
sn = ask("Special Notes")
@entry
para "Dear diary, The date is " + n2 + ". It is " + w2 + ". I will go to " + a2 + "."
para "Yesterday was " + n1 + ". It is " + w1 + ". I will go to " + a1 + "."
para "Tomorrow is " + n3 + ". It is " + w3 + ". I will go to " + a3 + "."
para "Today was " + tw + ". " + sn + "I am feeling " + m + "."
button "Save", :width => 85 do
file = ask_save_file
File.open(file, "w+") do |f|
@file.text = File.write(@entry.text)
end
end
end