Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I created a completely empty ruby file emptyrubyfile.rb, saved it, and then opened my terminal app, dropped into $ irb, and loaded it > load 'emptyrubyfile.rb'. The output returned was => > true, which seems, to me, to be the expected output.
I then exited irb, > exit, and dropped into pry $ pry. I loaded the same empty file > load 'emptyrubyfile.rb', but the output returned was => *. To escape the * I can use either exit or quit.
I realize that irb and pry, are similar, but different. My question is: what is the difference and why does the pry output expect more input from me and what is it asking me for at the * prompt?
You would have missed the ending ' while loading it in pry. There is no difference between irb and pry on this aspect. I'm guessing you typed
> load 'emptyrubyfile.rb
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
My very first Ruby program: hello_world.rb:
puts ¨Hello World¨
I have saved it and when I try to run it from terminal, it returns:
ruby hello_world.rb
hello_world.rb:1:in `<main>': uninitialized constant World¨ (NameError)
I tried installing reinstalling ruby AND the editor(ATOM). That is really all I could think of to try. Any ideas would really help
-ruby 3.0.1p64. Ubuntu
Your string is not wrapped in double-quotes (") but in ¨ characters.
Replace
puts ¨Hello World¨
with
puts "Hello World"
You probably copy as pasted puts "Hello World" from some website whose formatting changes the quotes. They are not valid quotes for strings. Retype the quotes yourself.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What does the 2nd "in" do? I can't seem to find this kind of example anywhere other than this one right here.
for a in in /home/davidwright/attachments/*/*.tar
do
echo "extracting $x"
tar -xvf $x
done
Looks like a typo. It means the loop iterates with the string "in" as the first value assigned to a, then proceeds to iterate over the results of the glob. The shell's just not that picky, and every item after the first in is a thing to iterate over in the for loop. Unless there is a file named in that is known to exist, tar will complain when it tries to unpack the non-existent in file.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to parse a hash in ruby. I have an array an array of 'entries'. I want to take each entity and get array of runs within it (I want to store the runs in a different variable as seen below). My problem is that runs always turns out nil. Below is my code:
entries = test_plan['entries']
entries.each do |ent|
puts "in entries"
puts ent
runs = ent['runs]']
runs.each do |run|
and what an 'entries' hash looks like.
{"id"=>"7", "suite_id"=>729, "name"=>"Regression", "runs"=>[{"id"=>2588, "suite_id"=>729}]}
There is a simple typo. Change
runs = ent['runs]']
to
runs = ent['runs']
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I don't know why this isn't working properly, it always gives me false.
More importantly is there an easy way to see line-by-line execution of the code? Something like an easy trace that would help me troubleshoot this (I tried irb, but couldn't get it to work with multiline example like this one).
puts 'enter a word and I will tell you if its a palindrome or not: '
word = gets.chomp
backwards = word.reverse
if word == backwards
puts "yes, it is a palindrome!"
else
puts "no, #{word} is not a palindrome."
end
EDIT:
Sorry, I had a typo in my word. This is working fine. I feel like an idiot. Which brings me to my second question above... a good way to trace code execution in irb or elsewhere... is that possible?
The pry gem is an excellent debugging tool.
https://github.com/pry/pry
Install it by typing on the command line...
gem install pry
Then in your code at the point you want to halt execution, enter this line
require 'pry'; binding.pry
You can then inspect all variables, even change them if you want, and type 'exit' when you're ready to resume.
If you do require 'pry' at the beginning of your program, you can just do binding.pry where you need to halt... in that case you don't need the two-command expression I used above.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When I type in ubuntu terminal:
$ rvm help use
The command output looks like:
M-bM-^HM-4 rvm use [ruby-string]
Setup current shell to use a specific ruby version.
...
What are the M-bM-^HM-4 characters? Should I use a special command to read the help?
This are unicode characters:
∴ rvm list
I see it too. Looks like it's just some weird characters that the documenter typed in before every instance of the term "rvm".
Likely on their console, it highlights the term, or something similar.