Thanks for all of you alls assist in getting over the confusion
1 Like
Sure however, as you’ll come to comprehend, SyntaxErrors
confuse the interpreter.
On this case the “sudden comma” (and 2nd argument,) is not the reason for the SyntaxError
it’s the symptom.
The principle error in your syntax was complicated the interpreter by separating an identifier (with an area) and what the interpreter thought was an expression enclosed in parenthesis.
Within the first use, with a single argument, the expression in parenthesis was evaluated to the array disney_movies
and that outcome handed to the strategy as a single argument.
However when the comma and one other expression true
was added, Ruby didn’t know the best way to consider what it although was an expression inside parenthesis.
When this house is eliminated, the interpreter appropriately sees a technique name with a number of arguments as a substitute of a reference identifier and a separate expression.
Should you had omitted the parenthesis, Ruby wouldn’t have been confused. Ie …
places "In backwards type: #{sortedlist disney_movies, true}"
… ought to have labored. (However most model guides are in opposition to methodology calls that don’t wrap the parameter lists in parenthesis.)
However I might counsel you learn the “Decide Axe” e-book.
It’s listed in my e-book record within the Ruby Assets lists.
1 Like
I can not discover that within the record
Sorry, sure, in the event you take a look at Programming Ruby you will notice it has a choose axe on the quilt.
Thanks, I’ll look it over
I bumped into bother once more
That is the script I received out of this video
Ruby Programming – 22 – Add an Merchandise to a Hash – YouTube
novels = {
Green_Eggs: 5,
Harry_Potter: 5,
Way_of_Kings: 4.
}
reply = "sure"
# provides a loop of asking the query whereas the reply is sure
whereas reply == "sure"
places "Would you want so as to add one other e-book to your hash? (Kind sure or no)"
reply = will get.chomp
# case is in case of this do that
case reply
when "sure"
places "What e-book would you want so as to add?"
e-book = will get.chomp
if novels [book.to_syn] .nil?
places "What ranking do you give it?"
ranking = will get.chomp
novels [book.to_sym] = ranking.to_i
places "#{e-book} has been added to your novels with a ranking of #{ranking}."
else places "That e-book is already in your Hash!"
finish
when "no"
places "Sounds good to me!"
else places "I don't perceive. Goodbye."
finish
finish
places "Here's what is in your hash now: #{novels}"
I get this error
Error: #<SyntaxError: <major>:4: syntax error, sudden '}', anticipating '('>
SketchUp:1:in `eval'
why is it anticipating a ( as a substitute of the }
am I doing the hash fallacious
The issue could also be with “4.”. I don’t suppose Ruby likes that naked “.” Attempt 4.0 if you need a float or simply 4 if you need an integer.
1 Like
Additionally the will get
methodology will instantly returns nil
-without ready to consumer input- in SketchUp Ruby console (I can’t clarify why), due to this fact you’ll get #<NoMethodError: undefined methodology
chomp’ for nil:NilClass>` afterward in your code.
so what do I take advantage of as a substitute of will get.chomp
In SketchUp you’d use an inputbox or HTMLdialog. Direct enter from the Ruby Console to a script would usually freeze SketchUp as a result of one can’t assume the Ruby Console is even open. The Ruby Console isn’t actually a terminal neither is it absolutely equal to irb (the Ruby interactive interpreter).