Module: Kernel

Defined in:
lib/finder/import.rb

Instance Method Summary collapse

Instance Method Details

#import(feature) ⇒ Object (private)

Evaluate script directly into current scope.

Raises:

  • (LoadError)


8
9
10
11
12
# File 'lib/finder/import.rb', line 8

def import(feature)
  file = Find.feature(feature, :absolute=>true).first
  raise LoadError, "no such file -- #{feature}" unless file
  instance_eval(::File.read(file), file) if file
end

#import_relative(fname) ⇒ Object (private)

Evaluate script directly into current scope relative to the current script.

Note this is implemented via #caller.first.

Raises:

  • (LoadError)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/finder/import.rb', line 20

def import_relative(fname)
  call = caller.first
  fail "Can't parse #{call}" unless call.rindex(/:\d+(:in `.*')?$/)
  path = $` # File.dirname(call)
  if /\A\((.*)\)/ =~ path # eval, etc.
    raise LoadError, "import_relative is called in #{$1}"
  end
  file = File.expand_path(fname, File.dirname(path))

  raise LoadError, "no such file -- #{file}" unless File.file?(file)

  instance_eval(::File.read(file), file) #if file
end