Skip to content

Instantly share code, notes, and snippets.

@yhara
Created September 2, 2017 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhara/1f39cd617689866926bc6a7cb10a99e9 to your computer and use it in GitHub Desktop.
Save yhara/1f39cd617689866926bc6a7cb10a99e9 to your computer and use it in GitHub Desktop.
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.
__DIR__
=> File.dirname(__FILE__)
File.dirname
__DIR__("../foo")
=> File.expand_path("../foo", File.dirname(__FILE__))
__dir__
__method__
File.expand_path("../foo", __dir__)
File.expand_path("../foo", File.dirname)
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
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment