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

  • Home
  • SEARCH
  • 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 7963449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:36:33+00:00 2026-06-04T05:36:33+00:00

Let me preface by stating I’m a new programmer – an IT guy trying

  • 0

Let me preface by stating I’m a “new” programmer – an IT guy trying his hand at his first “real” problem after working through various tutorials.

So – here is what I’m trying to do. I’m watching a directory for a .csv file – it will be in this format: 999999_888_filename.csv

I want to return each part of the “_” filename as a variable to pass on to another program/script for some other task. I have come up w/ the following code:

require 'rubygems'
require 'fssm'

class Watcher

def start
  monitor = FSSM::Monitor.new(:directories => true)
  monitor.path('/data/testing/uploads') do |path|
    path.update do |base, relative, ftype| 
      output(relative)
    end
    path.create do |base, relative, ftype| 
      output(relative)
    end
    path.delete { |base, relative, ftype| puts "DELETED #{relative} (#{ftype})" }   
  end
  monitor.run
end


def output(relative)
  puts "#{relative} added"
  values    = relative.split('_',)
  sitenum  = values[0]
  numrecs  = values[1]
  filename = values[2]
  puts sitenum
 end
end

My first “puts” gives me the full filename (it’s just there to show me the script is working), and the second puts returns the ‘sitenum’. I want to be able to access this “outside” of this output method. I have this file (named watcher.rb) in a libs/ folder and I have a second file in the project root called ‘monitor.rb’ which contains simply:

require './lib/watcher'

watcher = Watcher.new
watcher.start

And I can’t figure out how to access my ‘sitenum’, ‘numrecs’ and ‘filename’ from this file. I’m not sure if it needs to be a variable, instance variable or what. I’ve played around w/ attr_accessible and other things, and nothing works. I decided to ask here since I’ve been spinning my wheels for a couple of things, and I’m starting to confuse myself by searching on my own.

Thanks in advance for any help or advice you may have.

  • 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-04T05:36:34+00:00Added an answer on June 4, 2026 at 5:36 am

    At the top of the Watcher class, you’re going to want to define three attr_accessor declarations, which give the behavior you want. (attr_reader if you’re only reading, attr_writer if you’re only writing, attr_accessor if both.)

    class Watcher
        attr_accessor :sitenum, :numrecs, :filename
    
        ... 
        # later on, use @ for class variables
        ...
            @sitenum = 5
        ...
    end
    

    Now you should have no problem with watcher.sitenum etc. Here’s an example.

    EDIT: Some typos.

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

Sidebar

Related Questions

Let me preface this question with first stating that I'm new to GUI interfaces:
First, let me preface this by saying that I'm brand-new to Ember.js and relatively
Let me preface the question by stating that I'm not a programmer and am
Preface Let me start off by saying that I'm a relatively new programmer and
Preface: I am an inexperienced java programmer handed one of his first assignments. If
First off, let me preface this question by stating that I'm really a pretty
First let me preface this question by saying that I'm fairly new to Javascript.
Let me preface by saying that I'm new to ant, and I'm using version
Let me preface by saying this is the first live cakephp project for me.
Let me preface this with the disclaimer that I am very new to multithreading

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.