以下代码向我显示错误如下:
"ruby -KU -- 'C:\Users\Ishmael\My Documents\Aptana Studio 3 Workspace\Simple\FirstFile'
C:/Users/Ishmael/My Documents/Aptana Studio 3 Workspace/Simple/FirstFile:55: syntax error, unexpected $end, expecting keyword_end"
我搜索了多余的结尾和尾随的 '.' 但徒劳无功,我仍然无法弄清楚为什么它不起作用!
class Greeter
attr_accessor :name
def initialize(name="dudes")
@name=name
end
def say_hi
if @name.nil?
puts "..."
else if @name.respond_to?("each")
@name.each do |name|
puts "Hello #{name.capitalize}!"
end
else
puts "Hi #{@name.capitalize}!"
end
end
def say_bye
if @name.nil?
puts "..."
else if @name.respond_to?("join")
puts 'Goodbye #{@name.join(", ").capitalize}! Come back soon!'
else
puts "Bye #{@name.capitalize}!"
end
end
end
if __FILE__ == $0
greeter = Greeter.new
greeter.say_hi
greeter.say_bye
greeter.name = "Ishmael"
greeter.say_hi
greeter.say_bye
greeter.name = ["Albert", "Brenda", "Charles", "Dave", "Englebert"]
greeter.say_hi
greeter.say_bye
greeter.name = nil
greeter.say_hi
greeter.say_bye
end