Is there any way to use DATA.readlines to read the data (below
__END__) in a file that's been required/included? I want the read
code to be inside the included/required file.
···
--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".
i don't think one can do it directly, but:
harp:~ > cat b.rb
require 'dynaload'
module M
def your_code_here_as_normal
end
end
···
On Fri, 24 Mar 2006, Bill Guindon wrote:
Is there any way to use DATA.readlines to read the data (below
__END__) in a file that's been required/included? I want the read
code to be inside the included/required file.
--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".
#
# add this to the end of the file
#
data = open(__FILE__)
data.each{|line| break if line =~ /^__END__$/}
Dynaload::export data, "name" => "DATA"
__END__
42
harp:~ > cat a.rb
require 'dynaload'
loaded = Dynaload::dynaload "b.rb"
obj, desc = loaded.objects.select{|obj, desc| desc['name'] == 'DATA'}.first
puts obj.read
harp:~ > ruby a.rb
42
regards.
-a
--
share your knowledge. it's a way to achieve immortality.
- h.h. the 14th dali lama
> Is there any way to use DATA.readlines to read the data (below
> __END__) in a file that's been required/included? I want the read
> code to be inside the included/required file.
>
> --
> Bill Guindon (aka aGorilla)
> The best answer to most questions is "it depends".
>
>
i don't think one can do it directly, but:
Thanks much, was hoping there was a more elegant solution. I was just
going to use it to avoid a 'here doc' block. Now, the 'here doc'
doesn't look so bad 
···
On 3/23/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
On Fri, 24 Mar 2006, Bill Guindon wrote:
harp:~ > cat b.rb
require 'dynaload'
module M
def your_code_here_as_normal
end
end
#
# add this to the end of the file
#
data = open(__FILE__)
data.each{|line| break if line =~ /^__END__$/}
Dynaload::export data, "name" => "DATA"
__END__
42
harp:~ > cat a.rb
require 'dynaload'
loaded = Dynaload::dynaload "b.rb"
obj, desc = loaded.objects.select{|obj, desc| desc['name'] == 'DATA'}.first
puts obj.read
harp:~ > ruby a.rb
42
regards.
-a
--
share your knowledge. it's a way to achieve immortality.
- h.h. the 14th dali lama
--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".