Last active
July 26, 2023 18:40
-
-
Save cybersamx/5d4f635e1d7a0f8ed264 to your computer and use it in GitHub Desktop.
Load and execute a Ruby script in Rails console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Say you need to run this script which is not part of your Rails app... | |
# Do the following: | |
# | |
# 1. Assume we put this script file in <Rails app root>/tmp | |
# 2. $ cd <Rails app root> | |
# 3. $ rails console | |
# 4. ruby > load "#{Rails.root}/tmp/script_to_run_in_rails.rb" | |
# 5. ruby > MyClass.echo | |
# Hello | |
# => nil | |
# | |
# Just run load again to reload the changes in script_to_run_in_rails.rb. | |
class MyClass | |
def self.echo | |
puts('Hello') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment