ruby中的错误:未定义的局部变量或方法

ruby中的错误:未定义的局部变量或方法,ruby,variables,methods,undefined,Ruby,Variables,Methods,Undefined,我在尝试编写ruby时出错。 错误:C:/Users/PC ASUS/Desktop/g.rb:3:in':未定义的局部变量或main:Object的方法“y”(NameError) 这是我的密码: puts " Do you like to install hacking pack?" insta_one = gets.chomp if insta_one == y make else puts "Ok. Bye!" end def make awe = file.new("shell.

我在尝试编写ruby时出错。
错误:C:/Users/PC ASUS/Desktop/g.rb:3:in
':未定义的局部变量或main:Object的方法“y”(NameError)

这是我的密码:

puts " Do you like to install hacking pack?"
insta_one = gets.chomp

if insta_one == y
make
else 
puts "Ok. Bye!"
end

def make
awe = file.new("shell.bat","w")
readme.puts("@echo off")
readme.puts("color a")
readme.puts("echo Installing hacking pack")
readme.puts("Thanks for downloading rootShell!")
readme.puts("My email - cyniclimbu@gmail.com")
end

y
不是字符串,而是未定义的变量

请更改第3行:

if insta_one == 'y'

在使用方法之前,需要先定义它。在您的代码中,
make
是在您尝试调用它之后定义的,因此ruby不熟悉它,并抛出一个错误:

def make
  File.open("shell.bat", 'w') do |readme|
    readme.puts("@echo off")
    readme.puts("color a")
    readme.puts("echo Installing hacking pack")
    readme.puts("Thanks for downloading rootShell!")
    readme.puts("My email - cyniclimbu@gmail.com")
  end
end

puts " Do you like to install hacking pack?"
insta_one = gets.chomp

if insta_one == 'y'
  make
else 
  puts "Ok. Bye!"
end

您正在将``nsta_one``与不存在的
y
变量进行比较。您想要的是:
如果insta_one==“y”
。谢谢,但现在它给我一个错误,即“make”未定义
make
is方法。在调用函数之前定义方法。在
make
方法中,请将
file.new(…
更改为
file.new(…
。因为
文件
是类,所以调用类方法时应该大写。它仍然会给我错误未定义的局部变量或方法。请将
自述文件
更改为
awe
,因为
自述文件
是未定义的变量,那么将使用此代码。