Solved

Ruby issue

Posted on 2012-12-24
7
285 Views
Last Modified: 2012-12-29
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
0
Comment
Question by:roy_sanu
  • 4
  • 3
7 Comments
 
LVL 26

Expert Comment

by:arober11
ID: 38718526
Split the line:

def amethod localvar = 10 puts( localvar )

Then run via:

irb variables.rb
0
 

Author Comment

by:roy_sanu
ID: 38718830
The error is in the snapshot
rubyerror.docx
0
 

Author Comment

by:roy_sanu
ID: 38720865
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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 26

Expert Comment

by:arober11
ID: 38726381
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.
0
 

Author Comment

by:roy_sanu
ID: 38726495
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
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 38726554
You need to invoke you defined methods  e.g.

Alter your variables.rb to:

localvar = "hello" ;
$globalvar = "goodbye"
def amethod
    localvar = 10
    puts( localvar )
    puts( $globalvar )
end
def anotherMethod
    localvar = 500
    $globalvar = "bonjour"
    puts( localvar )
    puts( $globalvar )
end
puts "Invoking: amethod"
amethod
puts "Invoking: anotherMethod"
anotherMethod

Open in new window


Then type:

ruby variables.rb
0
 

Author Comment

by:roy_sanu
ID: 38728982
thank you it is working on

irb variables.rb
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now