From: Magnus Holm Date: 2010-05-12T18:35:38+09:00 Subject: [ruby-core:30178] Re: [Problem] DATA and __END__ in a loaded rb file Right now you'll have to do something like: data = File.read(__FILE__) =~ /^__END__\n/ && $' || '' // Magnus Holm On Wed, May 12, 2010 at 10:33, Charles Cui wrote: > how to get global constant DATA in file ,if a.rb is loaded by b.rb. > when b.rb is exec by Ruby,even if the DATA is used in a.rb,infact the DATA > is from b.rb, > because a.rb is loaded by b.rb. > how to resolve it? > such as: > : > Cui$ cat /usr/local/ruby-1.8.7-p160/bin/roadrunner > #!/usr/local/ruby-1.8.7-p160/bin/ruby > # > # This file was generated by RubyGems. > # > # The application 'roadrunner' is installed as part of a gem, and > # this file is here to facilitate running it. > # > require 'rubygems' > version = ">= 0" > if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then > ����version = $1 > ����ARGV.shift > end > gem 'roadrunner', version > load Gem.bin_path('roadrunner', 'roadrunner', version) > > #this is code > __END__ > #!/usr/bin/env ruby > #main.rb > #this is the DATA