Test mon code source de la classe avec certains exigent code et je continue à avoir l'erreur suivante:erreur de charge Ruby cannt charge tel fichier
"D:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require':cannot load such file -- ./xxx.rb (LoadError) from D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require' from xxx.rb:1:in ''
Voici le code que je utilise pour tester mon code:
require "./proj6colecio.rb.txt"
print " "
guitar = Guitar.new("Stratocaster", "Fender", "Solid Body", 6, "Black")
print "Guitar Name: #{guitar.name}\n"
print "Guitar Brand: #{guitar.brand}\n"
print "Guitar Type: #{guitar.type}\n"
print "Number of Strings: #{guitar.strings}\n"
print "Guitar Color: #{guitar.color}\n"
print guitar, "\n"
Pas vraiment éduqué dans les erreurs rubis sur les rails encore comme je suis encore étudiant, apprendre les bases de la programmation.
Merci beaucoup pour tous les commentaires
# Guitar class with instance variables @name, @brand, @type @strings @color and
# method take_strings.
class Guitar
# initialize method is called when user invokes Guitar.new.
def initialize(the_name, the_brand, the_type, the_strings, the_color)
@name = the_name
@brand = the_brand
@type = the_type
@strings = the_strings
@color = the_color
end
# Define getters
def name
return @name
end
def brand
return @brand
end
def type
return @type
end
def strings
return @strings
end
def color
return @color
end
# define setters
def strings=(value)
@strings = value
end
def to_s
return "The Guitar is a #{name} made by #{brand}. It is a #{type} with #{strings} strings and is #{color}."
end
def change_color
@color = "Blue"
end
end
guitars = [ ]
guitars << Guitar.new("Stratocaster", "Fender", "Solid Body", 6, "Black")
guitars << Guitar.new("Les Paul", "Gibson", "Solid Body", 6, "Yellow")
guitars << Guitar.new("White Falcon", "Gretsch", "Semi-Hollow", 6, "White")
# Print all guitars
guitars.each do |g|
print g, "\n"
end
#Change color of guitar to blue
guitars.each do |g|
g.change_color
end
guitars.each do |g|
print g, "\n"
end
end
Pourquoi "require" ./proj6colecio.rb.txt "'? Peut-être 'require" ./proj6colecio.rb "' –
ya que j'ai pris le .txt juste eu pour lire le fichier sans éditeur de texte à l'école – RubyNovice
mais toujours ne fonctionne pas – RubyNovice