Smoke Signals

Friday, February 25, 2005

Ruby Syntax (things to remember)

One that had me looking sideways like a puppy was what is called a symbol. Symbols are use quite a bit in rails and me being the whole-view-of-the-picture-or-I-just-don't-get-it kind of guy I had to understand what the hell they were.

Here is an example of a symbol... :symbolName, or constantVar :symbolName. Here is how Introduction to Ruby for MacOSX describes them: Symbols are used to represent method and instance variable names and can also act as unique values for constants.

So here's where they are weird(to me) They can be used as an enum, an immutable string, also used in accessors(getter and setter) which I think it implemented by the object class eg. attr_accessor :counter. Representing methods eg. fp = m.method( :myMethod ) to use fp.call().

Another idiom that I found strange was the whole methoName? which essentially means that the method is going to return a boolean. I am used to strongly typed C# and dynamic python where you explicitly return true or 1 in python.

1 Comments:

Post a Comment

<< Home