Solved

Ruby issue

Posted on 2012-12-24
7
293 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rails 3 paperclip mime type - Office 2007 documents 3 1,325
Finding all occurrences 2 222
Javascript: handler for multi-select dropdown 8 113
ruby gem installation 2 53
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

837 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