Cannot repeat my first lesson in Ruby

I was trying to follow along with a video
sketchup ruby console program for beginners - quick tutorial - YouTube
when I tried to put in the first line that she typed
I tried using the word first and the word firstl like she did
this is what I get
first *[30,10,0]
Error: #<NoMethodError: undefined method `first’ for main:Object>

:in `' SketchUp:1:in `eval'

firstl *[30,10,0]
Error: #<NoMethodError: undefined method `firstl’ for main:Object>

:in `' SketchUp:1:in `eval'

even when I tried putting a space after the * I got this

first * [30,10,0]
Error: #<NameError: undefined local variable or method `first’ for main:Object>

:in `'

can anyone tell me what I did wrong

It looks like you used a multiplication sign, " * ", instead of an equal sign, " = ".

Here’s what it looks like when a multiplication sign is used:

Screenshot 2023-01-07 071450

Here’s what it looks like if an operator is left out:

Screenshot 2023-01-07 071648

You need to use an " = " to assign the values to the variables.

Screenshot 2023-01-07 072031

Fix the syntax and it will work.

Also, in the future, don’t use images to show your code. Instead, use a triple back tick, " ``` " (on the tilde key, upper left of keyboard). Just put the back ticks in before and after your code and it will show like the following:

first1 = [30, 10, 0]
=> [30, 10, 0]

second = [30, 30, 0]
=> [30, 30, 0]

third = [60, 30, 0]
=> [60, 30, 0]
fourth [60, 10, 0]
Error: #<NoMethodError: undefined method `fourth' for main:Object>
<main>:in `<main>'
SketchUp:in `eval'
=> nil
fourth = [60, 10, 0]
=> [60, 10, 0]
fourth2 *[10, 20, 30]
Error: #<NoMethodError: undefined method `fourth2' for main:Object>
<main>:in `<main>'
SketchUp:in `eval'
=> nil
1 Like
# test
first = [30,10,0]
1 Like

ok, thankyou. I think I got this part now

So the video shows something like this:

model = Sketchup.active_model

first = [30, 10, 0]
second = [30, 30, 0]
third = [60, 30, 0]
fourth = [60, 10, 0]

model.entities.add_line(first, second, third, fourth, first)

The code specifies four points and then adds lines between them.

You might want to give Ruby Console+ or Ruby Code Editor a try. They make it a bit easier to see what’s going on.

I recommend you to use Ruby Console+ extension (by Aerilius).


I never dreamed that the video was showing the -= sign, I thought it was using the * sign. My video was blurry thought. I am using both Ruby Console and Ruby Code Editor

Look at the gear icon below the YouTube Video(s). Click and increase the “Quality” setting to improve video visibility.

NotePad or NotePad++ might be useful to you as well. Good luck!

Thank you for the reminder about the video quality setting on YouTube. But in this instance the problem was I downloaded the video at a low resolution. I am going to have to download these types of videos at higher resolution. I will be using NotePad when writing rb files.

Don’t use the native Notepad, it is not a code editor.

Use NotePad++ or VS Code

1 Like

I have Ruby Code Editor extension. What would be the pros and cons between using it and NotePad++

I’m sorry, but this is not a full featured stand alone coder editor application.
It is web dialog that simulates a code editor for learning and coding small snippets.

I don’t have time nor desire to go into all the pros and cons.

Thank you, what you told me was enough I think. I will differently have to get NotePad ++