Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7927253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:12:59+00:00 2026-06-03T19:12:59+00:00

I this working Ruby code that i want to make an executable from with

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:13:01+00:00Added an answer on June 3, 2026 at 7:13 pm

    There is no write method on the File class. You have to first open the file and can then write to it. It can be done similar to this:

    Dir.glob("*.txt").each do |file|
      File.open(file, 'w') {|f| f.write replace(File.read(file))}
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this working in an old code that I didn’t end up using...
I'm working on some Ruby code that needs to create primary keys on existing
Had this working; at one stage. The problem is the following text is now
I have this working definition: IDENTIFIER [a-zA-Z][a-zA-Z0-9]* I don't want to keep repeating the
I was working with the lotrepls Ruby interpreter, and I want like to write
The Problem I'm working on a problem that involves sharding. As part of the
In a Ruby project I'm working with a badly formed xml file that comes
So I'm working through the Ruby Koans , and I've encountered an issue that
I think this question is a matter of writing nice ruby code, let me
Working on a little Ruby script that goes out to the web and crawls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.