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?
Ruby 1.9 help:
Take a look on: