Method: #shebangify

Defined in:
lib/crazy_ivan/vendor/lockfile-1.4.3/install.rb

#shebangify(f) ⇒ Object

}}}



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/crazy_ivan/vendor/lockfile-1.4.3/install.rb', line 65

def shebangify f
#{{{
  open(f) do |fd|
    buf = fd.read 42 
    if buf =~ %r/^\s*#\s*!.*ruby/o
      ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
      begin
        fd.rewind
        ftmp.puts "#!#{ $ruby  }"
        while((buf = fd.read(8192)))
          ftmp.write buf
        end
        ftmp.close
        yield ftmp.path
      ensure
        ftmp.close!
      end
    else
      yield f
    end
  end
#}}}
end