Very rank beginner.

R

Ropebender

Help. I am a really new beginner looking at Ruby for the first time.
I was trying to go through the tutorial "Ruby in 20 minutes" on a Windows XP
machine using fxri.

Some of the code does not work as in the examples. Who should I ask for
help?

Thanks for any suggestions (even flames are welcome )

Van!!
 
T

Tim Greer

Ropebender said:
Help. I am a really new beginner looking at Ruby for the first time.
I was trying to go through the tutorial "Ruby in 20 minutes" on a
Windows XP machine using fxri.

Some of the code does not work as in the examples. Who should I ask
for help?

Thanks for any suggestions (even flames are welcome )

Van!!

What site were you using the ruby tutorial from? What parts of the code
didn't work, what were the problems or errors? If you've tried the
code and searched for answers, then you'd probably ask here.
 
R

Ropebender

The tutorial was on http://www.ruby-lang.org/

It was the tutorial in the sidebar "Ruby in 20 minutes"

Worked fine until I tried to define a class Greeter. Instructions said to
initialize Greeter with (name = "World") and then define an object g to set
the @name. It didn't woork like the tutorial said.

=> nil

irb(main):033:0> class Greeter

irb(main):034:1> def initialize(name = "World")

irb(main):035:2> end

irb(main):036:1> def say_hi

irb(main):037:2> puts "Hi #{@name}!"

irb(main):038:2> end

irb(main):039:1> def say_bye

irb(main):040:2> puts "Bye #{@name}!"

irb(main):041:2> end

irb(main):042:1> end

=> nil

irb(main):043:0> g = Greeter.new("Pat")

=> #<Greeter:0x63075a4>

irb(main):044:0> g.say_hi

Hi !

=> nil

irb(main):061:0> g = Greeter.new("Andy")

=> #<Greeter:0x62e3924>

irb(main):062:0> g

=> #<Greeter:0x62e3924>

irb(main):063:0>





Looks like the initialize never worked. Any suggestions?
 
P

Pascal J. Bourguignon

Ropebender said:
The tutorial was on http://www.ruby-lang.org/

It was the tutorial in the sidebar "Ruby in 20 minutes"

Worked fine until I tried to define a class Greeter. Instructions said to
initialize Greeter with (name = "World") and then define an object g to set
the @name. It didn't woork like the tutorial said.

=> nil

irb(main):033:0> class Greeter

irb(main):034:1> def initialize(name = "World")

irb(main):035:2> end

Looks like the initialize never worked. Any suggestions?

Indeed. def initialize(name = "World") doesn't initialize anything.
It just says that if you don't give any argument to new, then it should
do as if you passwed "World", and set the parameter accordingly.

You didn't do anything with this parameter.
Try to add a
@name = name
somewhere...
 
R

Ropebender

Sure enough ..

I left that line out. In the tutorial, the "@name" was in blue, and I
interpreted it as a response from ruby rather than a line I type in. Sorry
for the error. I have a LOT to learn :)\
 
T

Tim Greer

Ropebender said:
Sure enough ..

I left that line out.  In the tutorial, the "@name" was in blue, and I
interpreted it as a response from ruby rather than a line I type in. 
Sorry for the error.  I have a LOT to learn :)\

No need to apologize, sometimes it just takes some patience or an extra
set of eyes to find the problem. I've seen a lot of professional
coders about throw their system out the window (literally) because of a
simple thing they were missing after a day of coding with no breaks.
Sometimes you have to take a break and look at it with fresh eyes.
 
P

Phlip

irb(main):033:0> class Greeter

Don't use irb. If you use Windows, the One Click Installer comes with SciTE.exe.
Run that, and it will run your ruby for you each time you hit <F5>.
 
R

Ropebender

Thanks for the tip ... Another question:

When I write an xxx.rb program in Notebook and try to run it, the cmd
window will not stay open. On earlier versions of Windows you could make a
..pif file to control if the window stayed open or closed, but in XP it seems
they have taken that away. I looked up all the commands and opening
perameters I could find and can't seem to find one that will cause the CMD
window to wtay open after the program runs so I can see the results. I
either need to do that, or redirect the output to LPT1 so I can see what I
did. Does SciTE allow you to read in and run a program from a file?

Thanks !

Van!!
 
R

Ropebender

Now I see, SciTE is an excelent looking universal Text Editor :) What a
find! I would have never found it but for your hint. Thanks loads! SciTE
will help in lots of ways.. Notebook -- never again :))

That answered the second question too, no, you can't run the program from a
text editor, Silly me. So I am left with the last one: how to keep the
blasted window open or redirect the output.

Van!!
 
R

Ropebender

A very rank beginner that doesn't follow instructions! F5 you say. Thanks
!! It works. Now all I have to do is learn the language.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top