鞋子写入文件时出错
Shoes error writing to file
我正在编写一个为用户写日记的程序,但是我遇到了一些麻烦...这是我的代码:
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
我知道这是一个小错误,但请帮助我好吗?
谢谢,丹尼尔 M.
更新:
问题解决了;我只需要将第一个 '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
我正在编写一个为用户写日记的程序,但是我遇到了一些麻烦...这是我的代码:
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
我知道这是一个小错误,但请帮助我好吗? 谢谢,丹尼尔 M.
更新: 问题解决了;我只需要将第一个 '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