Avatar of roy_sanu
roy_sanu
Flag for India asked on

Ruby issue

Can some body tell me when i run the ruby script as variable.rb, i am getting the error  in the command line, pls find the snapshot of it


localvar = "hello"
$globalvar = "goodbye"
def amethod localvar = 10 puts( localvar )
puts( $globalvar ) end
def anotherMethod localvar = 500
$globalvar = "bonjour"
puts( localvar )
puts( $globalvar )
end
variables-error.docx
Ruby

Avatar of undefined
Last Comment
roy_sanu

8/22/2022 - Mon
arober11

Split the line:

def amethod localvar = 10 puts( localvar )

Then run via:

irb variables.rb
roy_sanu

ASKER
The error is in the snapshot
rubyerror.docx
roy_sanu

ASKER
Here is the changes below when i run Ruby script in the command line i donot get any error but i donot see any output of "puts"
=======================================================
localvar ="hello"
globalvar ="goodbye"
def amethod localvar =10
puts( localvar )
puts( globalvar )
end
def anotherMethod localvar =500
globalvar ="bonjour"
puts( localvar )
puts( globalvar )
end
variable-error.docx
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
arober11

Per the error messages, and my post above, you need to split your def lines.

Can you please paste the text of you command windows, into a CODE block, or alternatively past the screen grabs into Paint, save as a jpg or png, and upload directly (the results will be visible on page), as it's a pain to have to download, scan for viruses and open a Word document, and a real pain when you only have a phone / tablet to hand.
roy_sanu

ASKER
Quack!!!!!!! quite strange------------still the no error no output

localvar ="hello"
globalvar ="goodbye"

def amethod
localvar = 10
puts( localvar )
puts( globalvar )
end

def anotherMethod
localvar = 500
globalvar ="bonjour"
puts( localvar )
puts( globalvar )
end
error.jpg
ASKER CERTIFIED SOLUTION
arober11

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
roy_sanu

ASKER
thank you it is working on

irb variables.rb
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.