Sha256: e5ef12e32ede3b9a991f142eae35110344e9a8c8c0e419be07dee4317a438536

Contents?: true

Size: 1012 Bytes

Versions: 3

Compression:

Stored size: 1012 Bytes

Contents

require 'facet/binding/eval'

class Binding

  # returns line number
  def __LINE__
    eval( "__LINE__" )
  end

  # returns file name
  def __FILE__
    eval( "__FILE__" )
  end

  # return the directory of the file
  def __DIR__
    eval( "File.dirname(__FILE__)" )
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCBinding < Test::Unit::TestCase

    def setup
      a = 1
      b = 2
      x = "hello"
      # the line number must be updated if it moves
      @bind = binding; @this_line_no = __LINE__
      @this_file_name = File.basename( __FILE__ ) # why does it equal basename only?
    end

    def test___LINE__
      assert_equal( @this_line_no, @bind.__LINE__ )
    end

    def test___FILE__
      assert_equal( @this_file_name, File.basename( @bind.__FILE__ ) )
    end

    def test___DIR__
      assert_equal( File.dirname( @bind.__FILE__ ), @bind.__DIR__ )
    end

  end

=end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-1.0.0 lib/facet/binding/__LINE__.rb
facets-1.0.3 packages/core/lib/facet/binding/__LINE__.rb
facets-1.1.0 lib/facet/binding/__LINE__.rb