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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:15:36+00:00 2026-06-14T02:15:36+00:00

I defined a custom instance method in the String class that I want to

  • 0

I defined a custom instance method in the String class that I want to use in my other ruby files. I can do it by require-ing the file (that I defined my custom method in), but I want to use it naturally (without having to require).

For example: I defined this in my ‘custom_string.rb’ file:

class String
  def set_style(style)
    puts "\n#{self}"
    self.size.times do
    print style
    end
  end
end

Then, to use my set_style method in my ‘test.rb’ file, I have to do this:

require 'custom_string'
puts "hello".set_style("*")

I’m not using a Rails project. Is there a way to include my file into ruby by default (from the ruby command line) so it is available to all files in Ruby?

  • 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-14T02:15:37+00:00Added an answer on June 14, 2026 at 2:15 am

    Ruby 1.9 help:

    $ ruby --help
    Usage: ruby [switches] [--] [programfile] [arguments]
      -0[octal]       specify record separator (\0, if no argument)
      -a              autosplit mode with -n or -p (splits $_ into $F)
      -c              check syntax only
      -Cdirectory     cd to directory, before executing your script
      -d              set debugging flags (set $DEBUG to true)
      -e 'command'    one line of script. Several -e's allowed. Omit [programfile]
      -Eex[:in]       specify the default external and internal character encodings
      -Fpattern       split() pattern for autosplit (-a)
      -i[extension]   edit ARGV files in place (make backup if extension supplied)
      -Idirectory     specify $LOAD_PATH directory (may be used more than once)
      -l              enable line ending processing
      -n              assume 'while gets(); ... end' loop around your script
      -p              assume loop like -n but print line also like sed
      -rlibrary       require the library, before executing your script
      -s              enable some switch parsing for switches after script name
      -S              look for the script using PATH environment variable
      -T[level=1]     turn on tainting checks
      -v              print version number, then turn on verbose mode
      -w              turn warnings on for your script
      -W[level=2]     set warning level; 0=silence, 1=medium, 2=verbose
      -x[directory]   strip off text before #!ruby line and perhaps cd to directory
      --copyright     print the copyright
      --version       print the version
    

    Take a look on:

    -rlibrary       require the library, before executing your script
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to invoke a method on a COM object that is defined in
I have a custom class that conforms to the MKAnnotation protocol. An instance of
Documentation states: Adds a user-defined custom member to an instance of a Windows PowerShell
I want to replace all instances of '::memcpy()' with my custom made 'customMemcpy()' defined
I defined a custom component and tried to use binding as the following: <ui:composition
I have defined a custom IPrincipal and custom IIdentity based on a website that
This method that uses method-level generics, that parses the values from a custom POJO,
When discussing metaclasses, the docs state: You can of course also override other class
I have defined a custom edge and vertex type to use in an undirected
I have a custom listView defined like this public class DDListView extends ListView implements

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.