# Howto run a non-app script in console

**URL:** <https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189>\
**Category:** Rails\
**Created:** [April 19, 2008, 12:13am UTC](https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189 "2008-04-19T00:13:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mat30](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@mat30](https://www.ruby-forum.com/u/mat30)\
**Post date:** [April 19, 2008, 12:13am UTC](https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189/1 "2008-04-19T00:13:01Z")

</div>

To save some typing I’d like to create and run any script in the console  
window.  
By ‘any script’ I mean non-application related, that is a script that  
doos not exist within the application structure.  
This would help in exploring stuff without retyping all the time.  
Thanks,  
Mat

---

<div class="post-metadata">

**Author:** ![mat30](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@mat30](https://www.ruby-forum.com/u/mat30)\
**Post date:** [April 19, 2008, 12:55am UTC](https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189/2 "2008-04-19T00:55:56Z")

</div>

Matthew Andersen wrote:

> To save some typing I’d like to create and run any script in the console  
> window.  
> By ‘any script’ I mean non-application related, that is a script that  
> doos not exist within the application structure.  
> This would help in exploring stuff without retyping all the time.  
> Thanks,  
> Mat

Like this?

$ cat \> test.rb  
puts ‘this is a test’  
^D  
$ ruby test.rb  
this is a test  
$

?

Stephan

---

<div class="post-metadata">

**Author:** ![mat30](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@mat30](https://www.ruby-forum.com/u/mat30)\
**Post date:** [April 19, 2008, 1:08am UTC](https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189/3 "2008-04-19T01:08:44Z")

</div>

Sorry, I was not too clear in my question.  
I ment Rails Console, where I’d like to run scripts that have access  
to the application environment but are NOT existing within the app  
structure.

Say I’d like to try building and testing a Class that does not exist  
(yet) in my application, or try bits of code to see how things work,  
without actually modifing any existing application code.

So far, I’ve been typing and retyping to explore Rails, but it would be  
nice to type my tests into a file, so I could build upon my new  
experience - and re-run the stuff the next time I get back to it.

Thanks again,  
Mat

---

<div class="post-metadata">

**Author:** ![mat30](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@mat30](https://www.ruby-forum.com/u/mat30)\
**Post date:** [April 19, 2008, 1:46am UTC](https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189/4 "2008-04-19T01:46:42Z")

</div>

Hi –

On Sat, 19 Apr 2008, Matthew Andersen wrote:

> So far, I’ve been typing and retyping to explore Rails, but it would be  
> nice to type my tests into a file, so I could build upon my new  
> experience - and re-run the stuff the next time I get back to it.

You can either load files while you’re in the console, or use  
script/runner, which will run Ruby scripts in the context of your  
application’s environment.

David

–  
Rails training from David A. Black and Ruby Power and Light:  
INTRO TO RAILS June 9-12 Berlin  
ADVANCING WITH RAILS June 16-19 Berlin  
INTRO TO RAILS June 24-27 London (Skills Matter)  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![mat30](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@mat30](https://www.ruby-forum.com/u/mat30)\
**Post date:** [April 19, 2008, 1:19am UTC](https://www.ruby-forum.com/t/howto-run-a-non-app-script-in-console/135189/5 "2008-04-19T01:19:07Z")

</div>

Matthew Andersen wrote:

> Sorry, I was not too clear in my question.  
> I ment Rails Console, where I’d like to run scripts that have access  
> to the application environment but are NOT existing within the app  
> structure.
> 
> Say I’d like to try building and testing a Class that does not exist  
> (yet) in my application, or try bits of code to see how things work,  
> without actually modifing any existing application code.
> 
> So far, I’ve been typing and retyping to explore Rails, but it would be  
> nice to type my tests into a file, so I could build upon my new  
> experience - and re-run the stuff the next time I get back to it.
> 
> Thanks again,  
> Mat

Like this then?

$ script/console

> > require ‘new\_test.rb’  
> > =\> true
> 
> > new\_test = NewTest.new(whathaveyou)  
> > =\> \<\>
> 
> > new\_test.run  
> > =\> true
> 
> >

Stephan
