Solved

Ruby issue

Posted on 2012-12-24
7
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rails 2.3.x link_to tag 1 496
Ruby problem with blocks 5 329
Upgrade Ruby from 1.8.7 to 1.9.2-p320 7 329
compare two windows registry keys in chef 1 81
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…

733 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