How can I create a bash script which runs irb, then some ruby code? The Next CEO of Stack OverflowHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to use specify version of ruby for shell script with rbenv?How can I syntax highlight Ruby range bounds in gtksourceview3.0?cpulimit on a bash script which runs other commandsBash script only runs in debug modeHow can I check the ruby format for a bunch of files and/or a single file?Ruby gems not recognized in bash scriptHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to iterate over files using awk, bash, or ruby?How can I use ruby gem commands like bundler when ruby is installed by nix package manager?Create Bash Script to Wait and then Run
What steps are necessary to read a Modern SSD in Medieval Europe?
Which one is the true statement?
Is fine stranded wire ok for main supply line?
Yu-Gi-Oh cards in Python 3
Physiological effects of huge anime eyes
What does "shotgun unity" refer to here in this sentence?
Is French Guiana a (hard) EU border?
Spaces in which all closed sets are regular closed
Ising model simulation
Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?
Towers in the ocean; How deep can they be built?
What day is it again?
Is it correct to say moon starry nights?
Expressing the idea of having a very busy time
Is there a way to save my career from absolute disaster?
Can you teleport closer to a creature you are Frightened of?
Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?
How to Implement Deterministic Encryption Safely in .NET
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Vector calculus integration identity problem
Won the lottery - how do I keep the money?
Is it professional to write unrelated content in an almost-empty email?
What is the process for purifying your home if you believe it may have been previously used for pagan worship?
Point distance program written without a framework
How can I create a bash script which runs irb, then some ruby code?
The Next CEO of Stack OverflowHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to use specify version of ruby for shell script with rbenv?How can I syntax highlight Ruby range bounds in gtksourceview3.0?cpulimit on a bash script which runs other commandsBash script only runs in debug modeHow can I check the ruby format for a bunch of files and/or a single file?Ruby gems not recognized in bash scriptHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to iterate over files using awk, bash, or ruby?How can I use ruby gem commands like bundler when ruby is installed by nix package manager?Create Bash Script to Wait and then Run
I'm trying to do this to make unit testing a breeze for myself.
The contents of an example script in question are as follows:
irb
require 'random_utils.rb'
a = SuccessChecker.new
Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.
bash ruby test
add a comment |
I'm trying to do this to make unit testing a breeze for myself.
The contents of an example script in question are as follows:
irb
require 'random_utils.rb'
a = SuccessChecker.new
Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.
bash ruby test
add a comment |
I'm trying to do this to make unit testing a breeze for myself.
The contents of an example script in question are as follows:
irb
require 'random_utils.rb'
a = SuccessChecker.new
Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.
bash ruby test
I'm trying to do this to make unit testing a breeze for myself.
The contents of an example script in question are as follows:
irb
require 'random_utils.rb'
a = SuccessChecker.new
Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.
bash ruby test
bash ruby test
edited Aug 8 '12 at 22:56
ac7v
asked Aug 8 '12 at 22:41
ac7vac7v
134
134
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You are executing commands sequentially, so the shell executes irb
, waits until irb
get closed and executes the next command (in your case require 'random_utils.rb'
)…
What you want is to provide the script to irb
via STDIN
irb <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
But this will probably not do what you want as irb
is for interactive use, you should consider using your normal ruby interpreter instead, e.g:
ruby <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
add a comment |
Looks like you're ready to take the next step and use a unit testing library.
Here's an introduction to minitest, built into Ruby 1.9.
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
add a comment |
A modern solution to this is to use the pry
gem and make this a plain old ruby script.
#!/usr/bin/env ruby
require 'pry'
require 'random_utils.rb'
a = SuccessChecker.new
binding.pry
will dump you into a debugger wherever binding.pry is...
New contributor
add a comment |
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f45099%2fhow-can-i-create-a-bash-script-which-runs-irb-then-some-ruby-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are executing commands sequentially, so the shell executes irb
, waits until irb
get closed and executes the next command (in your case require 'random_utils.rb'
)…
What you want is to provide the script to irb
via STDIN
irb <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
But this will probably not do what you want as irb
is for interactive use, you should consider using your normal ruby interpreter instead, e.g:
ruby <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
add a comment |
You are executing commands sequentially, so the shell executes irb
, waits until irb
get closed and executes the next command (in your case require 'random_utils.rb'
)…
What you want is to provide the script to irb
via STDIN
irb <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
But this will probably not do what you want as irb
is for interactive use, you should consider using your normal ruby interpreter instead, e.g:
ruby <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
add a comment |
You are executing commands sequentially, so the shell executes irb
, waits until irb
get closed and executes the next command (in your case require 'random_utils.rb'
)…
What you want is to provide the script to irb
via STDIN
irb <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
But this will probably not do what you want as irb
is for interactive use, you should consider using your normal ruby interpreter instead, e.g:
ruby <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
You are executing commands sequentially, so the shell executes irb
, waits until irb
get closed and executes the next command (in your case require 'random_utils.rb'
)…
What you want is to provide the script to irb
via STDIN
irb <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
But this will probably not do what you want as irb
is for interactive use, you should consider using your normal ruby interpreter instead, e.g:
ruby <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
answered Aug 8 '12 at 23:00
Ulrich DangelUlrich Dangel
20.7k25971
20.7k25971
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
add a comment |
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.
– ac7v
Aug 8 '12 at 23:21
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.
– Ulrich Dangel
Aug 8 '12 at 23:25
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.
– ac7v
Aug 8 '12 at 23:32
add a comment |
Looks like you're ready to take the next step and use a unit testing library.
Here's an introduction to minitest, built into Ruby 1.9.
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
add a comment |
Looks like you're ready to take the next step and use a unit testing library.
Here's an introduction to minitest, built into Ruby 1.9.
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
add a comment |
Looks like you're ready to take the next step and use a unit testing library.
Here's an introduction to minitest, built into Ruby 1.9.
Looks like you're ready to take the next step and use a unit testing library.
Here's an introduction to minitest, built into Ruby 1.9.
answered Aug 10 '12 at 16:41
CawflandsCawflands
1012
1012
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
add a comment |
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!
– ac7v
Aug 13 '12 at 3:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
Cool, hope you enjoy it :)
– Cawflands
Aug 13 '12 at 7:03
add a comment |
A modern solution to this is to use the pry
gem and make this a plain old ruby script.
#!/usr/bin/env ruby
require 'pry'
require 'random_utils.rb'
a = SuccessChecker.new
binding.pry
will dump you into a debugger wherever binding.pry is...
New contributor
add a comment |
A modern solution to this is to use the pry
gem and make this a plain old ruby script.
#!/usr/bin/env ruby
require 'pry'
require 'random_utils.rb'
a = SuccessChecker.new
binding.pry
will dump you into a debugger wherever binding.pry is...
New contributor
add a comment |
A modern solution to this is to use the pry
gem and make this a plain old ruby script.
#!/usr/bin/env ruby
require 'pry'
require 'random_utils.rb'
a = SuccessChecker.new
binding.pry
will dump you into a debugger wherever binding.pry is...
New contributor
A modern solution to this is to use the pry
gem and make this a plain old ruby script.
#!/usr/bin/env ruby
require 'pry'
require 'random_utils.rb'
a = SuccessChecker.new
binding.pry
will dump you into a debugger wherever binding.pry is...
New contributor
New contributor
answered 2 days ago
StephenStephen
101
101
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f45099%2fhow-can-i-create-a-bash-script-which-runs-irb-then-some-ruby-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown