Newbie confusion and dejection

Over the years I have taught myself to program in C, C++, and VB to
build apps to run in WIndows, along with the scripting languages
necessary to set up a website
I have built websites using PHP, Ajax, and MySql but am just a
hobbyist and my basic knowledge of how systems work is very patchy.
I have limited experience of linux, enough to get me by with what I
need to use SSH when necessary on my website’s shared server.

Now, for my sins, I am trying to learn RoR.

I have no problem following the language tutorials but I am lost when
it comes actually running a ruby app or script in windows (or anywhere
else for that matter). I had been hoping to use RoR on my website.
I can create a Rails framework on the server but decided I needed to
learn more about Ruby before I did any more work there.

I have installed the following:
InstantRails
Cygwin

The Ruby directory has ruby.exe which opens a command line window and
rubyw.exe which does nothing when I click it.

I am using the Pragmatic Programmers Guide and Simply Rails2 by
Patrick Lenz as my learning tools.

I am wallowing about in irb and the Ruby console opened from the
Rails control panel playing about with classes etc and learning the
syntax of the language but achieving nothing else. The console seems
to be a very limited playground when it comes to trying out things
quickly. e.g. in irb I cannot paste anything into the console.
Am I missing something here?

When I learn a language I usually manage to cobble together a simple
hello world type of executable app or script and build on my mistakes
from there. but I cannot work out how to do this or get a ruby script
running. Given time I guess i will work it out but woud be grateful if
someone here could advise me what I should be doing next to master
ruby and RoR.

Thanks
Reg

From: “Reg” [email protected]

When I learn a language I usually manage to cobble together a simple
hello world type of executable app or script and build on my mistakes
from there. but I cannot work out how to do this or get a ruby script
running.

I’m not trying to discourage you from learning Rails, but
you may be interested to know there are equally powerful
alternatives.

Take a look at how simple it is to get a “Hello, World”
app going in Ramaze:

http://ramaze.net/learn/getting-started

I realize this just boils down to personal preference, but
I never liked the way Rails likes to generate a skeleton
of dozens of files when beginning a new app.

In contrast, frameworks like Ramaze let you start simple,
and add complexity when you decide you need it.

Regards,

Bill

2009/4/13 Bill K. [email protected]:

alternatives.
In contrast, frameworks like Ramaze let you start simple,
and add complexity when you decide you need it.

Regards,

Bill

This is going to sound silly but until I got into unit testing I could
never really think about what I wanted to do but had to think about
how to do it. Mike C. has writen an excellent guide to unit
testing [0] and it’s a bloody fast way to actually learn Ruby from the
ground up.

Before:
/me: OK. I can use ri --this and ri --that but now I am ri
Bored::shitless of all of this documentation. I want to start actually
writing stuff but keep having to think about how it’s done.

after:
/me: kapow! shazaam. Now I can test what I know. I’ll see where my
stuff goes wrong. Ah. So that’s how you use an array, huh? Take
that! kaplow! So that’s what you mean by regexp? So I think that I can
get an IP address like this /\d+\d+\d+\d+/.

and I can now test bits of my code whilst I am thinking about what I
want to do.

That make sense?

[0] http://clarkware.com/cgi/blosxom/Ruby?_start=6


John M.
07739 171 531
MSc (DIC)

Timezone: GMT

On Sun, 12 Apr 2009 23:40:08 -0500, john maclean [email protected]
wrote:

writing stuff but keep having to think about how it’s done.

[0] http://clarkware.com/cgi/blosxom/Ruby?_start=6

It makes sense and did not sound silly, but these further questions
are going to sound silly and a bit pathetic too. I have been coddled
too long in programming environments like Macromedia Dreamweaver and
MS Visual Studio

  1. Mike C. says " Now, let’s run the test." What is he running it
    in? Is that the Ruby console?
  2. Is there some way to write an app that will run as a windows
    graphical user interface?
  3. I am currently using the ConText editor. Is there an equivalent of
    the MSVisualBasic IDE?
  4. Should I be setting up a Ubuntu partition an learn Ruby in there?

Thanks for your patience
Reg

On Mon, Apr 13, 2009 at 4:05 PM, Reg [email protected] wrote:

On Sun, 12 Apr 2009 23:17:25 -0500, Bill K. [email protected] wrote:

Thanks Bill - it’s all grist to the mill

What?
You need to type your script up in a text editor, i hear notepad is
great
for a starter. Then you need to save the file, as for example hello.rb .
Then you need to open up a terminal window and type ‘ruby hello.rb’.
Here
is your hello world in ruby;

puts ‘Hello, World! God help us all!’

On Sun, 12 Apr 2009 23:17:25 -0500, Bill K. [email protected] wrote:

alternatives.
In contrast, frameworks like Ramaze let you start simple,
and add complexity when you decide you need it.

Regards,

Bill

Thanks Bill - it’s all grist to the mill

On Mon, Apr 13, 2009 at 4:45 PM, Reg [email protected] wrote:

MS Visual Studio
Reg

Fair enough. I use netbeans with the ruby extensions, it is quite good for
managing a project. There are many ways to do gui work, apparently shoes
is
a favorite but if you want a RAD you might be better off with gtk and
glade
as a platform. You don’t need to run ubuntu, actually it would probably
just
confuse the issue for you since you have to learn a new environment to
make
it useful.

On Mon, 13 Apr 2009 02:07:26 -0500, john maclean [email protected]
wrote:

luck.
Thanks you guys.
Thus has all been a great help. I am getting on top of it now.
Reg

2009/4/13 Dylan E. [email protected]:

You need to type your script up in a text editor, i hear notepad is great
users. Nobody ever uses it." - Andrew S. Tanenbaum

I wrote a simple code generator that would create a two files; a ruby
template file and a test_the_script.rb to test the script in that
file. Who cares what editor/IDE/OS I used? </insert your fave tool>
works for you and </emacs, vim, Debian/> works for me [a] ;-). Point
is that I wrote it in ruby and say `ruby generate_new_script.rb. to
generate the two files.

With unit testing in the file " test_generate_new_script.rb" I test
the script “generate_new_script.rb”, so that I can check that my
thinking was right whilst I was writing the script.

Also, my knowledge base grows at the rate that I learn as I write
more productive code. I hate notes, as they are easy to write. For me
tests are a nice way of saying to myself “STFU and code! Stop
collecting bookmarks, STFU and…”

I would strongly suggest that you spend sometime with that url [0].
You’ll learn how you learn Ruby.

[a] Disclaimer: Works For Me Technolgy is copyright of Jayeola.
Anything else that works is either completely beyond me or just pure
luck.


John M.
07739 171 531
MSc (DIC)

Timezone: GMT

Reg wrote:

I am using the Pragmatic Programmers Guide and Simply Rails2 by
Patrick Lenz as my learning tools.

Rails isn’t Ruby. I read the book “Agile Web D. with Rails” and
it seemed quite neat. But not my cup of tea.

If you’re new to Ruby try something simpler like “Everyday Scripting
with Ruby”. To play with the language, use something like Scite.

Dylan E. wrote:

You need to type your script up in a text editor, i hear
notepad is great for a starter. Then you need to save
the file, as for example hello.rb .
Then you need to open up a terminal window and type
‘ruby hello.rb’.
Here is your hello world in ruby;
puts ‘Hello, World! God help us all!’

You should make a directory on your disk for doing this,
e.g., c:/ruby . Tell the text editor to save the script
you write into that directory. When you open the terminal
window, change to that directory – cd c:/ruby . (I haven’t
used MS Windows for ten years, but I think that’s right.)

You can test Ruby code without using that Unit Test framework.
Using one of the examples that was given for unit testing,
write the following code into a file called “foo.rb” in the
Ruby directory, and then type “ruby foo.rb” in the terminal
window (without the quotes) after cd’ing to that directory:

x = “Rick”.index(‘t’)
puts x.class
puts x

The interpreter will print this:

NilClass
nil

You’ve tested what happens when the “index” method is run
on the string “Rick” (and requested the index of a character
that isn’t in the string). The result is assigned to a
variable x. First it prints the class of the result, and
then its value.

If you change the ‘t’ to ‘c’ in the code, it prints this:

Fixnum
2

So the expression yields an integer whose value is the
place of the character in the string.

To me, this is simpler than creating a unit test for each
little bit of code you want to play with, and you don’t
have to guess a value and put it into an “assert”
statement. You simply print out the value produced by
the code you’re testing (which can be a single expression
or a large program) and also print its class. If “puts”
can’t print out the value of some complex result object,
at least you know the class of the result, and can try
to find a way to print it out.

You are using one of the simplest and most powerful
debugging techniques – putting print statements in
your code! Of course in a larger body of code you can
put multiple print statements to see what’s going on.

One more suggestion: if you put this line in a Ruby file:

END

the interpreter will ignore everything that follows; won’t
even syntax check it. So if you want to test lots of
pieces of code (which you will when learning Ruby), you
can move the ones you’ve already tested to a place in the
file after the END line and save them there along with
a copy of what they printed out (use the mouse to copy and
paste it) and any comments you care to write. That way
you don’t have to make a separate file for each test.

On Mon, Apr 13, 2009 at 9:30 AM, Reg [email protected] wrote:

I have installed the following:
InstantRails
Cygwin

The Ruby directory has ruby.exe which opens a command line window and
rubyw.exe which does nothing when I click it.

Cygwin might be installing its own ruby that shadows one from
instantrails. One thing you could try doing is installing msys and
using the msys prompt to run ruby stuff from, rather than the cygwin
prompt.

martin

On Sun, Apr 12, 2009 at 9:00 PM, Reg [email protected] wrote:

I have no problem following the language tutorials but I am lost when
rubyw.exe which does nothing when I click it.
Neither of those should normally be clicked (you could run ruby.exe
and type code into the console window and then hit Ctrl-Z and it would
run the code, but that’s not really a good way to work!); they are the
interpreter executables. They should be invoked with a command line
that includes the script to execute (usually) along with other
options, if needed. Whatever basic Ruby book you have should have a
section on running Ruby (in Programming Ruby, its in Chapter 1,
“Getting Started”, under the heading “Running Ruby”, which is on pp.
5-7 in the second edition.)

 I am using the Pragmatic Programmers Guide and Simply Rails2 by
Patrick Lenz as my learning tools.

Which Pramatic Programmers book are you referring to? Programming
Ruby
(“the Pickaxe”) or Agile Web D. with Rails? The first
is good for learning Ruby, the second is good for learning Rails but
does very little to teach you how to use Ruby. It sounds like you need
more on getting off the ground with Ruby (and maybe more on the
Windows command-line environment, which unfortunately I can’t give you
any pointers on, being spoiled, in a sense, from being raised in the
era of DOS when there wasn’t a choice besides learning the command
line.

I am wallowing about in irb and the Ruby console opened from  the
Rails control panel playing about with classes etc and learning the
syntax of the language but achieving nothing else. The console seems
to be a very limited playground when it comes to trying out things
quickly. e.g. in irb I cannot paste anything into the console.

You can paste into irb the same way you paste into any console window
in Windows, but note (that because Ctrl+ combinations have
special meanings in the console), this isn’t the same way you paste
into other apps. And since the Windows Command Prompt window doesn’t
have a menu bar, you might not even no it had menu commands other than
the normal window controls that are attached to the application icon,
but it does; go to the "C:" icon in the corner of the window, select
Edit, and then Paste to paste material from the clipboard in to the
console window. (Edit->Mark and then either Enter on the keyboard or
Edit->Copy to copy from the console window.)

 When I learn a language I usually manage to cobble together a simple
hello world type of executable app or script and build on my mistakes
from there. but I cannot work out how to do this or get a ruby script
running.

Suppose your script is saved in c:\Documents and Settings\Me\My
Documents\source\ruby\helloworld.rb

Open a command prompt window. It should open with c:\Documents and
Settings\Me as the default path (where “Me” is your username on your
windows machine.)

  1. At the prompt, type cd my documents\source\ruby
  2. You should now be in the right directory, so type ruby helloworld.rb
  3. Your script should run.

As for some questions later in the thread: There are lots of libraries
(and one custom Ruby distribution, Shoes) for GUI app development in
Ruby, but you are probably best getting the hang of Ruby before
jumping into GUI development (though if you want to dive headfirst
into that pool, Shoes is probably the easiest place to start; see
www.shoooes.net, and yes, all those o’s are necessary.) For IDE
support, there are both Netbeans and Eclipse Ruby plugins (Netbeans
Ruby plugin is available as part of the distribution); and some
standalone Ruby IDE efforts. I prefer Netbeans Ruby support
personally,

Thank you all for being so wonderfully helpful.
I have learned something useful from each of your replies.

Dejected no longer I am getting into simple projects using the
NetBeans IDE. Ruby is indeed a great language.

Reg