Solved

Ruby issue

Posted on 2012-12-24
7
289 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ruby on Rails Installation Error 5 315
rails 2.3.x link_to tag 1 477
Command-line ruby: Spawn and control multiple daemons 3 404
What does 'resources :users' do in rails 1 276
Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

16 Experts available now in Live!

Get 1:1 Help Now