I this working Ruby code that i want to make an executable from with exerb on a windowspc.
When i compile hello_world.rb there is no problem running the executable but with this code
Exerb creates my executable but when i run it i get following error
undefined method `write' for File:Class (NoMethodError)
Here the code
def replace text
replacements = [
{:pattern => /(^ARFD0001\|.*)(FAC_12125)/, :replace_with => '\1FAC_12102'},
{:pattern => /^ARFD0001\|121\|25\|ZIEFAC\|/, :replace_with => 'ARFD0001|121|02|ZIEFAC|'},
{:pattern => /(^ARFD0010\|.*)(12125203)(\d{3})/, :replace_with => '\112102181\3'},
{:pattern => /(^ARFD0010\|.*)(2030341401)/, :replace_with => '\1181701500'},
{:pattern => /(^ARFD0019\|.*)(12125203)(\d{3})/, :replace_with => '\112102181\3'},
{:pattern => /(^ARFD0019\|\d*\|\d*\|\d*)(\|{2})/, :replace_with => '\1|PRINT|'},
{:pattern => /^ARFD0009\|121\|25\|/, :replace_with => 'ARFD0009|121|02|'}
].each{|replacement|text.gsub!(replacement[:pattern], replacement[:replace_with])}
text
end
Dir.glob("*.txt").each{|file|File.write(file, replace(File.read(file)))}
#line above gives the error in Exerb
How to get this going ? There is nothing wrong with the code, in the Ruby interpreter this works but it seems i have to tell Execrb to include the File class.
There is no write method on the
Fileclass. You have to first open the file and can then write to it. It can be done similar to this: