Howto run a non-app script in console

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

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

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

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 for details and updates!

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs