Require question

Hi guys!

I’m trying to write a simple source filter . For that purpose I created
a module which , when included into a script , it should filter the
operations .This is the filter module

module Filter
def self.recreate(file)
lines = File.read(file)
puts lines
raise SystemExit
end
end

if(FILE != $0)
Filter.recreate($0)
end

and this is the script :

require “filter”

[shell]some shell command goes here[/shell]

If i’m running the script directly (ruby script.rb), I’m receiving the
following error :
z.rb:3: syntax error, unexpected tIDENTIFIER, expecting $end
[shell]some shell command goes here[/shell]

I understand that ruby gives me an error , but I thoght that because the
Filter module kicks in first , it can process the source file before it
reaches the interpreter .

If I run the script like : ruby -rfilter script.rb , I see the output
of the script on the console . How could I make the script behave that
way just by including the

require “filter”

line? I hope there is another solution than :
#!/usr/bin/ruby -rfilter

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs