Module: Kernel

Defined in:
lib/sane/pp.rb,
lib/sane/sane_random.rb,
lib/sane/require_relative.rb

Overview

Constant Summary collapse

OriginalDir =

try to accomodate for later Directory changes…

File.expand_path(Dir.pwd)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.require_relative(relative_feature) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sane/require_relative.rb', line 7

def require_relative(relative_feature)
  c = caller.first
  # could be spec.sane.rb:127
  # or e:/abc.rb:127
  e = c.rindex(/:\d+/)
  file = $`
  if /\A\((.*)\)/ =~ file # eval, etc.
    raise LoadError, "require_relative is called in #{$1}"
  end
  absolute_feature = File.expand_path(File.join(File.dirname(file), relative_feature))
  begin
    require absolute_feature
  rescue LoadError => e
    # hacky kludge in case they've changed dirs...
    begin
      require File.expand_path(File.join(OriginalDir,File.dirname(file), relative_feature))
    rescue LoadError => ignore_me
      raise e # don't mask...
    end
  end
  
end

Instance Method Details

#__DIR__Object

BASE_DIR = Dir.getwd



63
64
65
66
# File 'lib/sane/sane_random.rb', line 63

def __DIR__
  dir = (/^(.+)?:\d+/ =~ caller[0]) ? File.expand_path(File.dirname($1), Dir.pwd) : nil
  dir
end

#pp(*objs) ⇒ Object



5
6
7
8
# File 'lib/sane/pp.rb', line 5

def pp(*objs)
   require('pp')
   pp(*objs) # use the new method
end