New to this language

Hey curt,

No I did'nt install this using the one-click installer. Truly speaking I don't know how I got this. Neways, I tried 2 things
1) Tried using irb from the secure shell that I am using. I just typed irb, and it says -bash: -irm: command not found
2) Since I have a windows machine, I tried using the command prompt window and from there I typed in irb. Hmm...but this Does not work either !

How do I go about getting irb, cos it sounds really kewl.

Thanks,
Vidhi.

···

-----Original Message-----
From: Curt Hibbs [mailto:curt@hibbs.com]
Sent: Friday, February 11, 2005 10:18 AM
To: ruby-talk ML
Subject: Re: new to this language

Ghelani, Vidhi wrote:> Sent: Friday, February 11, 2005 12:08 PM

Hey,

"(btw. what os are you using?)" ...I am using windows xp. But the
way I am working on this is, I connect to a secure shell network,
using putty, and I am connect using an IP address of a linux
machine. Now, is there any way I could work on this using windows itself?

Did you install using the one-click installer?

If so then you've got a number of tools at your disposal (see the Ruby entry
in your start menu). For irb, just open a command window and execute the
command "irb". This will put you in an environment where each line of Ruby
code you type will be executed when you press enter,

Curt

Thanks,
Vidhi.

-----Original Message-----
From: Brian Schröder [mailto:ruby@brian-schroeder.de]
Sent: Friday, February 11, 2005 10:00 AM
To: ruby-talk ML
Subject: Re: new to this language

On Sat, 12 Feb 2005 02:46:52 +0900 > "Ghelani, Vidhi" <vidhi.ghelani@intel.com> wrote:

> Hey ,
>
> How do I get IRB?? How is this different from using SSH ?

chances are good it is installed together with the ruby
interpreter. Just try to enter irb at the command line. (btw.
what os are you using?)

It has got nothing to do with ssh. I'll show you a typical irb session:

---
bschroed@black:~$ irb
irb(main):001:0> 1+5
=> 6
irb(main):002:0> 3.times do puts "welcome to ruby" end
welcome to ruby
welcome to ruby
welcome to ruby
=> 3
irb(main):003:0> require 'complex'
=> true
irb(main):004:0> I = Complex.new(0, 1)
=> Complex(0, 1)
irb(main):005:0> 12 + I
=> Complex(12, 1)
irb(main):006:0> (12 + I) * (2 - I)
=> Complex(25, -10)
irb(main):007:0> exit
bschroed@black:~$
---

>
> Also, can I have different classes in a file, that are not
subclasses of one another? Using your example, could I have a
class in that file that was not a subclass of Greet?

Yes you can. Seems it was not such a good example.

I recommend:
http://www.ruby-doc.org/docs/ProgrammingRuby/
http://www.ruby-doc.org/docbar/

and buy the dead tree version of the pickaxe second edition.

regards,

Brian

>
> Thanks,
> Vidhi.
>

>
> -----Original Message-----
> From: Brian Schröder [mailto:ruby@brian-schroeder.de]
> Sent: Friday, February 11, 2005 9:37 AM
> To: ruby-talk ML
> Subject: Re: new to this language
>
> On Sat, 12 Feb 2005 02:15:18 +0900 > > Jim Menard <jimm@io.com> wrote:
>
> > Vidhi,
> >
> > Welcome to Ruby.
> >
> > > 1) Just like in C++ you have a .h and a .cpp file , In this
language how
> > > would you store your file. In other words if I open emacs
and want to
> > > write a very simple small class in what format would I save
this file ?
> >
> > You store all your code in .rb files. There is no separate
header file. You
> > declare and define a class in one place, just like in Java.
(That's not
> > strictly true; in Ruby you can "re-open" a class and add more
methods later.
> > Don't worry about that yet.)
> >
> > superclass.rb:
> >
> > class Superclass
> > attr_accessor :super_instance_var
> > def initialize
> > @super_instance_var = 42
> > end
> > end
> >
> > myclass.rb
> >
> > require 'superclass'
> >
> > class MyClass < Superclass
> > attr_accessor :my_instance_var
> > def initialize
> > @my_instance_var = 'hello'
> > end
> > end
> >
> > another.rb
> >
> > require 'myclass'
> >
> > mc = MyClass.new
> > puts mc.my_instance_var
> > puts mc.super_instance_var
> >
> > > 2) How do you compile your code? What is the syntax?
> >
> > Ruby is an interpreted language, which means that it doesn't
need to be
> > compiled before you run it. To run "another.rb" above, type
> >
> > ruby another.rb
> >
> > > 3) Do you need a main and a makefile ? I am sure you would
need a main
> > > to test it . If yes how do you save the main? In what format?
> >
> > You don't need a main method. All Ruby code is executed as it
is seen by the
> > interpreter. Some of the code above (superclass.rb and
myclass.rb) define
> > classes and some of the code (another.rb) creates an instance
of a class and
> > prints some output.
> >
>
> one thing I want to add, is that you need not create a seperate
file per class. You can as well group classes by functionality
and put multiple classes in one file. (I think using one file per
class is a java idiom).
>
>
> first.rb
> class Greet
> def initialize(name)
> @name = name
> end
> end
>
> class GreetEnglish < Greet
> def greetme
> puts "Hello #{name}"
> end
> end
>
> class GreetGerman < Greet
> def greetme
> puts "Hallo #{name}"
> end
> end
>
> class GreetSpanish < Greet
> def greetme
> puts "Hola #{name}"
> end
> end
>
> greeters = [GreetEnglish, GreetGerman, GreetSpanish]
> greeter = greeters[rand(greeters.length)].new
> greeter.greet
>
> is perfectly reasonable and allowed. (Though maybe not two good
design, and you can shorten this alot when you have learned about
dynamic programming).
>
> And additionally, if you want to play with the language use
irb, the ruby interactive shell.
>
> good luck and enjoy ruby,
>
> Brian
>
>

--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 2/10/2005

Ghelani, Vidhi wrote:

Hey curt,

No I did'nt install this using the one-click installer. Truly
speaking I don't know how I got this. Neways, I tried 2 things
1) Tried using irb from the secure shell that I am using. I just
typed irb, and it says -bash: -irm: command not found
2) Since I have a windows machine, I tried using the command
prompt window and from there I typed in irb. Hmm...but this Does
not work either !

How do I go about getting irb, cos it sounds really kewl.

Go here:

  http://rubyinstaller.rubyforge.org/

and follow the download link. Download the latest version of the installer
(182-14). Once you have installed ruby from you should find a number of use
tools in you start menu under "Ruby", and you should be able to run "irb"
from the command line to get into an interactive ruby session.

Curt