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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:00:34+00:00 2026-06-02T19:00:34+00:00

I have to Ruby files: one contains a module with some methods for statistical

  • 0

I have to Ruby files: one contains a module with some methods for statistical calculation, in the other file I want to call one of the methods in the module.
How can I do that in Ruby?

Is that the right way?

require 'name of the file with the module'

a=[1,2,3,4]
a.method1
  • 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-02T19:00:35+00:00Added an answer on June 2, 2026 at 7:00 pm

    Require needs the absolute path to the file unless the file is located in one of Ruby’s load paths. You can view the default load paths with puts $:. It is common to do one of the following to load a file:

    Add the main file’s directory to the load path and then use relative paths with require:

    $: << File.dirname(__FILE__)
    require "my_module"
    

    Ruby 1.8 code that only loads a single file will often contain a one-liner like:

    require File.expand_path("../my_module", __FILE__)
    

    Ruby 1.9 added require_relative:

    require_relative "my_module"
    

    In the module you will need to define the methods as class methods, or use Module#module_function:

    module MyModule
      def self.method1 ary
        ...
      end
    
      def method2
        ...
      end
      module_function :method2
    end
    
    a = [1,2,3,4]
    MyModule.method1(a)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to have one ruby file that can require all
I am reading one file using ruby in which I have written regexp in
I have some command-line ruby scripts for things like pre-processing text files before uploading
How can I discover if two given files have the same permissions in Ruby?
I have a ruby file as follows: module Example class Myclass def t_st Hello
I have a ruby one-liner ruby1.9 -ine '#some statement' src/** . I assumed, like
TLDR: What can you do to combine multiple CoffeeScript files into one JS file,
I have one server which has nothing but xls log files. Each file is
I have a Ruby code with different classes in a few files. In one
so i have ruby script that simply writes to a test.txt file with hello

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.