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 8255419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:31:02+00:00 2026-06-08T01:31:02+00:00

I am receiving the following error when running my code below /Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1423:in stat’: No

  • 0

I am receiving the following error when running my code below

/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1423:in stat': No such file or directory - file.txt (Errno::ENOENT)
from /Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1423:in
block in fu_each_src_dest’
from /Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1439:in fu_each_src_dest0'
from /Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1421:in
fu_each_src_dest’
from /Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:391:in cp'
from learn3.rb:65:in
execute’
from learn3.rb:83:in block in execute'
from learn3.rb:83:in
each’
from learn3.rb:83:in execute'
from learn3.rb:103:in
‘

I had some issues installing BREW a couple weeks back. Could this be the cause of the problem in some way?

POSTED IS MY CODE


require 'fileutils.rb'

class Command
  # Allows us to read the description
  attr_reader(:description)

  # Initializes the class instance with the description command
  def initialize(description)
    @description = description
  end

  def execute
  end
end



class CreateFile < Command
  # Inherits from the Command class
  # Initialzied with two arguments 
  def initialize(path, contents)
    # Initialized description from parent class
    super("Create file: #{path}")
    @path = path
    @contents = contents
  end

  def execute
    # Open the file as writable
    f = File.open(@path, "w")
    # Write the contents to the file
    f.write(@contents)
    # Close the file
    f.close
  end
end



class DeleteFile < Command
  # Inherits from the Command class
  def initialize(path)
    # Initialize with the path
    super("Delete file: #{path}")
    # Inherits the description from Command class
    @path = path
  end

  def execute
    # Delete the file
    File.delete(@path)
  end
end



class CopyFile < Command
  def initialize(source, target)
    super("Copy file: #{source} to #{target}")
    @source = source
    @target = target
  end

  def execute
    FileUtils.cp(@source, @target)
  end
end



class CompositeCommand < Command
  # Inherits description and execute
  def initialize
    @commands = []
  end

  def add_command(cmd)
    @commands << cmd
  end

  def execute
    # Execute each command in the @commands array
    @commands.each { |cmd| cmd.execute }
  end

  def description
    description = ''
    # Each description neatly printed on its own line
    @commands.each { |cmd| description += cmd.description + "\n" }
    # Return all the descriptions 
    description
  end
end


cmds = CompositeCommand.new
puts cmds.description
cmds.add_command(CreateFile.new('file1.txt', "hello world\n"))
cmds.add_command(CopyFile.new('file.txt', 'file2.txt'))
cmds.add_command(DeleteFile.new('file1.txt'))
puts cmds.description
puts "Now executing all the commands"
cmds.execute
puts cmds.description
  • 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-08T01:31:03+00:00Added an answer on June 8, 2026 at 1:31 am

    You have a typo in source file name at line cmds.add_command(CopyFile.new('file.txt', 'file2.txt'))

    Changes this line to cmds.add_command(CopyFile.new('file1.txt', 'file2.txt'))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am receiving the following error in my code (c#, .Net 3.5, VS2008) when
I am receiving an error on the following line of code: Object reference not
I am receiving the following error when running a cap deploy:update failed: sh -c
Background I'm receiving the following error when trying to render a partial view in
I am receiving the following error in PHP Notice undefined offset 1: in C:\wamp\www\includes\imdbgrabber.php
I am receiving the following error when I try to send mail using a
I seem to be intermittently receiving the following error: BigQuery error in query operation:
I'm trying to implement my own GenericIdentity implementation but keep receiving the following error
I am importing an android app into Eclipse. I am receiving the following error
I am receiving this mysql error and i don't know why. I am following

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.