0
어떻게해야합니까 instantiate Foo에서 bar.rb
?루비와 Foo를 인스턴스화 하시겠습니까?
[email protected]:~/ruby/hello$
[email protected]:~/ruby/hello$ cat foo.rb
#file: foo.rb
class Foo
def initialize
puts "foo"
end
end
[email protected]:~/ruby/hello$
[email protected]:~/ruby/hello$ cat bar.rb
#file: bar.rb
require 'foo'
Foo.new
[email protected]:~/ruby/hello$
[email protected]:~/ruby/hello$ ruby bar.rb
/home/thufir/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- foo (LoadError)
from /home/thufir/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from bar.rb:2:in `<main>'
[email protected]:~/ruby/hello$
현재 모듈을 사용하지 않습니다.
[email protected]:~/ruby/hello$
[email protected]:~/ruby/hello$
[email protected]:~/ruby/hello$ ruby bar.rb
foo
[email protected]:~/ruby/hello$
[email protected]:~/ruby/hello$ cat bar.rb
class Foo
def initialize
puts "foo"
end
end
Foo.new
[email protected]:~/ruby/hello$