File: __dir__.rb

package info (click to toggle)
ruby-ramaze 2012.12.08-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,060 kB
  • ctags: 1,200
  • sloc: ruby: 10,446; makefile: 8
file content (25 lines) | stat: -rw-r--r-- 859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#          Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the MIT license.

module Ramaze
  module CoreExtensions
    # Extensions for Object
    module Object
      unless defined?(__DIR__)

        # This is similar to +__FILE__+ and +__LINE__+, and returns a String
        # representing the directory of the current file is.
        # Unlike +__FILE__+ the path returned is absolute.
        #
        # This method is convenience for the
        #  File.expand_path(File.dirname(__FILE__))
        # idiom.
        def __DIR__(*args)
          filename = caller[0][/^(.*):/, 1]
          dir = File.expand_path(File.dirname(filename))
          ::File.expand_path(::File.join(dir, *args.map{|a| a.to_s}))
        end
      end
    end # Object
  end # CoreExtensions
end # Ramaze