我是一个新的 ruby 人,我试图制作一个小程序,但有些东西困扰着我,我找不到解决方案。请给我提意见。我正在使用 Ubuntu 12.04
会有3个文件。main.rb、create.rb 和 check.rb
当我运行这个问题时,我遇到了这样的错误;
initialize': undefined method
dirpathname=' 用于 CheckDir:Class (NoMethodError)
[main.rb]
#!/usr/bin/env ruby
BASE_DIR = File.join('','home','local','tester','code','www','test')
APP_ROOT = File.dirname(__FILE__)
$:.unshift(File.join(APP_ROOT, 'lib'))
require 'create'
THEME_DIR = ARGV[0]
if !THEME_DIR
puts "Usage: ruby #{__FILE__} <the name of theme directory>\n\n"
exit!
end
sym = CreateSymlink.new(THEME_DIR)
sym.launch!
[创建.rb]
#!/usr/bin/env ruby
require 'check'
class CreateSymlink
def initialize(path=nil)
CheckDir.dirpathname = BASE_DIR + "/" + path
if CheckDir.dir_exists?
puts "The #{path} is already existed! Bye."
exit!
end
end
def launch!
puts "yeah"
#lets_start(path)
end
end
[检查.rb]
#!/usr/bin/env ruby
class CheckDir
@@dirpathname = nil
def self.dirpathname(path=nil)
@@dirpathname = File.join(BASE_DIR, path)
end
def self.dir_exists?
if @@dirpathname && File.directory?(@@dirpathname)
return true
else
return false
end
end
提前致谢