참고 : 나는 질문의 일부를 잘못 읽었고 다른 부분은 어떻게 든 나를 피했다 ... 나는 큰 시간을 멀티 태스킹해야했을 것입니다. 어쨌든,이 대답은 질문의 절반 만 대답하고 잘못 대답합니다. 그냥 말해. 당신은 소켓을 사용할 수, 청소기 및 방법을 이제
$ cat definer.rb
class Foo
def greet(person)
puts "Hello, #{person}!"
end
end
Bar = Class.new
$ cat finder.rb
$LOAD_PATH << File.dirname "."
before = Object.constants
require 'definer'
after = Object.constants
print (before - after).join(" ")
$ cat looker.rb
differences = `ruby finder.rb`.split(" ")
puts "The following constants will be defined when finder.rb is loaded: #{differences.join(", ")}"
:
좋아, 여기 가능성이 저렴한 방법이지만, 이런 일을하려고합니다. 나는 이것에 대한 예를 얻을 것이다. 당신이 Hello
쓸 때
autoload :Hello, 'x/hello'
autoload :Goodbye, 'x/goodbye'
, 당신은 실제로 Hello
일정에 액세스 :
없음
을 ¹. 소스 파일은 전체적으로로드되고 평가됩니다. 별도의 파일을 사용하지 않는 이유는 무엇입니까? –
Hello 클래스를 독점적으로로드하는 데 소요되는 시간과 메모리는 컴퓨터와 함께 Goodbye를로드하는 것보다 큽니다. – benzado