Swaroop C H

blog books about contact subscribe

Ruby-India First Meetup

12 Mar 2005

Today was the first meetup of the Ruby-India group (I wanted to announce this on my blog yesterday but the net connection was down at home :|, <sarcasm>all hail Sify</sarcasm>). I wanted to attend the intro Ruby talk basically because Premshree yaks about Ruby so much, I realized it was better that I understood a bit of Ruby before I lost my sanity. Just kidding!

The meetup was at 4 pm at Avik's office (Itellix) on Residency Road. First, we had the initial introductions from everyone - there were about 15 of us from many different companies. Yogi, from Thoughtworks, conducted the first session on coding in Ruby. He was mainly writing a program that works like the find program in Unix and in the process, was demonstrating the syntax and features in Ruby. I didn't understand some stuff like the use of :, @, @@ as prefixes to identifiers but I did get a brief understanding of the language. It sort of helped that I have a Python background but IMHO, a more formal first session that goes through the basics (like my 'Slither away with Python' presentation) would have been better for the newbies like me.

Ruby India Meetup Martin and the guys at the back Premshree and the guys in the front

In-between Yogi's session, lots of guys started coming in. Soon, there were about 30 people jampacked into the small room! I officially declared that we have achieved 'closure'. Heh. When Martin came in, I looked at him, then turned to Premshree and then to Bret and thought "What's with Ruby and guys with long hair ?!"... Oh well. Then, my colleagues Rajaram, Tahir and Suhas came in. Then, I realized there were 7 Yahoos in the room!

Next up was Bret's talk on Watir and Selenium. Bret is also from Thoughtworks and is one of the guys working on the Watir and Selenium projects. Watir is an Internet Explorer-based tool written in Ruby for automated testing of websites. Selenium is a Thoughtworks-sponsored project also about web-testing, but it works across browsers and platforms (yes, it works on Firefox on Linux). Bret explained about how both of these software work and how they are designed. I was pretty impressed with their ease of use and the comprehensive testing that can be done.

Bret Pettichord explaining Selenium Bret explaining Ruby India Meetup Selenium Selenium

The only drawback to Selenium is that it works best only when the websites are written with testing in mind. It won't work for existing websites. Selenium is actually not Ruby-specific - it is more of an architecture and you can write programs for it in Python, Ruby, Java, .NET and other languages as well. Their website should have more details on that.

On the way back home, I kept thinking that I wasn't convinced yet about Ruby. Most of the stuff I came across could have been done easily in Python. However, I believe in Alan Perlis's statement "A language that doesn't affect the way you think about programming, is not worth knowing." So I wanted to know more about Ruby and try to 'think in Ruby' before actually thinking about its pros and cons and stuff.

Earlier, Prem had suggested that the Pragmatic Programmer's Guide to Ruby was probably a good place for me to start. So, I opened it up and started reading. I wanted to try out the interactive prompt that was used to showcase Ruby all evening. As explained in the book, I used eval.rb :

[code] $ locate eval.rb /usr/share/doc/ruby-1.8.1/sample/eval.rb

$ ruby /usr/share/doc/ruby-1.8.1/sample/eval.rb ruby> a = 'Hello, world!' "Hello, world!" ruby> puts a ERR: undefined local variable or method `a' for main:Object [/code]

Yikes! I don't understand what I'm doing wrong here. I hope the ruby-ers can help me out here? I haven't even got past the preface of the book! I don't know if this info is useful but I am using Fedora Core 3. Also, I don't have irb installed on my system.

Maybe Ruby doesn't like me. Maybe snakes are friendlier than stones. Maybe ....

Update: After a yum install irb, which also upgraded Ruby to 1.8.2, I have the 'Hello World' program running using irb (short for interactive ruby).

Comments

Martin DeMello says:

Don't use eval.rb (which is just a toy sample app), use irb, which is what was used during the demos. The problem with eval.rb is that it uses eval(), which creates a binding to which the local variables are scoped. Here's the same thing in an irb session:

irb(main):001:0> a = 5
=> 5
irb(main):002:0> a
=> 5

Martin DeMello says:

Oh, and if you're dead set on not installing irb, the best way to learn is to edit the script in a file and save and run it each time. FreeRIDE is a fullfledged IDE that ships with ruby, or there's Scite (text editor, also ships with ruby) that lets you hit F5 to run the current script.

Swaroop C H says:

Martin: I guess I am going to have to use `irb`. What I do not understand is that the book clearly shows the same set of lines running correctly - why doesn't it work here?

Swaroop C H says:

Ian: I got the impression that Selenium will not work with any arbitrary website, for example, if you have written your website using Rails, then it is easy to test it using Selenium. This is what I understood. Please correct me if I am wrong.

Swaroop C H says:

Bret: After installing `irb`, things are smooth. I guess I'll come to the @ and @@ part later when reading the book. I also have to check out if the second edition is available in the local bookstores.

Martin DeMello says:

Not too sure - might be some change in scoping of locals and eval between 1.67 and 1.82. Try it with a non-local variable such as @a or $a and it'll work.

Avik Sengupta says:

Selenium will work with any arbitrary website. The issues only are about the language bindings... AFAIK currently, if you want to write you TESTS in ruby, you can only use them to test apps written in ruby... etc. The tests are actually run as javascript inside the browser.. so you either write them in javascript directly, or use the language binding of you server. There are language bindings for... eg.. python, java, C# ...

Ian Bicking says:

I have been working some with Selenium lately, though I haven't had a chance to do real testing yet. I don't think it really requires your application to be written for testing. They make a big deal about the Javascript security thing, and that Selenium is hosted on the same server as your application, but that's actually not a big deal at all -- you just have to unpack the Selenium distribution onto the same host. It's easier to just do this than try to do any of the complicated workarounds.

Bret Pettichord says:

The @ and @@ stuff is pretty simple. A variable called foo is just a local variable. If it is called @foo, then it is an instance variable; it belongs to the object. If it is called @@foo, then it is a class variable, and is the same for all objects of the class. If it is $foo, then it is global.

The stuff about eval.rb in the Ruby book is confusing, especially because it is at the front of the book. The rest of the book is better. Better yet, get the second edition.

Feedback

There's no comment box, but please do email me or tweet me your thoughts and criticisms, and I will publish the relevant ones here.