Exploring Ruby

I spent some time exploring and playing with Ruby this last week. I used Google to help with some of the items I was testing. I wish there was some type of accuracy score Google could assign web pages because I ran into some with inaccurate information. The following are some random comments from my testing.

“rspec” (Ruby’s test runner) does not provide informative error messages when Ruby fails. The info provided when a test failed was okay, but not when Ruby failed. I kept getting an error about an unexpected end statement, but it didn’t make sense. I finally figured out that it didn’t like the beginning class line because I had spelled it “Class”. I didn’t realize Ruby was case sensitive. From my time with JavaScript, I capitalized “Class” because you capitalize other keywords in JavaScript like “Object” or “Array”. Once I changed the spelling to be “class” the error went away, but I had chopped up my code by then trying to figure out the error.

I found differing ways of handling classes with inheritance on Google. I changed it around before I fixed the class spelling so I am not sure if either way will work. I saw examples like this:

class BaseClass

   class DiffClass < BaseClass

   end

end

where the class inheriting from the base class was within the base class definition. I also saw it where it was outside of the base class definition. I ended up with it outside the class, but I was still getting the error from the class misspelling so I don't know if the above technique would work, but it seems wrong to me.

I also saw a couple of ways of handling class properties. I saw references like "self.property" and "@property". I tried the "self.property" first since it was similar to the JavaScript technique of "this.property". I didn't get any syntax errors, but I did get errors from rspec showing that the tests failed. When I switched to "@property", everything passed. I still don't understand why, but I will keep playing around with it to try and figure it out.

Overall, I enjoyed exploring Ruby and intend to spend some more time with it.

Leave a Reply

Your email address will not be published. Required fields are marked *