首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >红宝石加载错误无法加载这样的文件

红宝石加载错误无法加载这样的文件
EN

Stack Overflow用户
提问于 2012-11-05 23:05:07
回答 2查看 1.3K关注 0票数 0

用一些需要的代码测试我的类源代码,我一直收到以下错误:

"D:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require‘:无法加载这样的文件-. ./xxx.rb (LoadError)从D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in’require‘from xxx.rb:1:in’

下面是我用来测试代码的代码:

代码语言:javascript
复制
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"

虽然我还是个学生,还在学习编程的基础知识,但还没有在rails错误方面接受过真正的教育。

非常感谢您的反馈

代码语言:javascript
复制
# 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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-06 00:10:04

试试require_relative

代码语言:javascript
复制
require_relative "proj6colecio.rb.txt"

另外,对于Ruby脚本,您也不需要.txt文件扩展名。

票数 1
EN

Stack Overflow用户

发布于 2012-11-05 23:55:09

这个语法不起作用,试一试require File.join( File.dirname( __FILE__ ), '..', 'proj6colecio.rb' )吧。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13241817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档