Он просто выведет две пустые строки на экран, когда он должен будет распечатать идентификатор карты и баланс
Я полностью переписал код.Я возился с этим кодом в течение часа
class RBC
def initialize
@args = ["Create a new card"]
@functions = ["create_rbc"]
puts "Do you have an RBC ID yet? Yes(0) No(1)"
hasrbc = gets.chomp.to_i
if hasrbc == 1
@balance = 5
create_rbc
else
login
end
end
def create_rbc
puts "\nGenerating your rbc\n\n"
puts "\nWelcome to your Ruby Binary Card(RBC)!\n\n"
puts "Your RBC will keep track of your RubyCredits(RC).\n"
puts "You will get paid RC for work apps, and pay for game apps.\n"
puts "If you lose track of your RBC ID, you can get a new one.\n"
puts "Doing this, however, will reset your balance to the default of $5\n\n"
puts "What is your name? Do first last\n"
@fullname = gets.chomp
@card_name = get_name_codec(@fullname)
@card_cipher = "#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}#{rand(1..9)}"
@card_id = "#{@card_name} - #{@card_cipher}"
instance_variable_set("@Id#{@card_cipher}", @balance)
puts "Write down your RBC ID: #{@card_id}"
file = File.open("Cards.rbc", "w")
file.puts @card_id
file.puts @balance
end
end
def get_name_codec(name)
names = name.split(" ")
fname = names[0]
lname = names[1]
fchar = fname.split(//)
fcodec = "#{fchar[0]}#{fchar[1]}"
name_codec = "#{fcodec}#{lname}"
return name_codec
end
def login
@found = false
puts "What is your RBC Id"
input = gets.chomp
File.open("Cards.RBC", "r") do |f|
f.each_line do |line|
if input == "#{line}"
@card_id = line.to_s
@found == true
elsif @found == true
@balance = line.to_i
end
end
end
puts "#{@card_id}#{@balance}"
end
RBC.new
Затем Cards.RBC
TiLan - 1122632527
5
Я хочу напечатать баланс и идентификатор карты.Он должен дать мне идентификатор моей карты, а затем остаток примерно так: 0000 ... и т. Д. 5