Jan
17
2007
In Ruby the implementation of a class is not closed. In Ruby, it is incredibly easy to add new methods to any existing class at runtime, even core system classes like String, Array, and Fixum. You just reopen a class and add new code. This language feature makes the language incredibly flexible. You might be wondering, why would you need this? Well, take a look at the API documentation of the Java String class. In most development organizations that I have been a part of we have had to write small string libraries that provide far more functionality that provided by the Java String class. The Apache Jakarta Commons Lang project provides a String helper class in StringUtils. StringUtils provides methods such as IsEmpty, Chomp/Chop, and LeftPad. StringUtils. StringUtils is a great class that has saved me from re-inventing the wheel several times, but it is another library to download, configure, learn, and import. Using the StringUtils class is more verbose calling a method on a string.
// Using StringUtils to trim a string.
str = StringUtils.trim(str);
// Calling a trim on a string.
str = str.trim();
Isn’t more concise and easier to read when you invoke a method on a string instead of using StringUtils? Unfortunately, even if an JCP is approved to add your custom string methods to the String class, the whole process is very time consuming. Each incremental release of Java takes years to develop. In Ruby, you can just reopen the String class to add the few methods you feel it lacks. To reopen the Ruby String class we can use the following code:
# reopen the class
String.class_eval do
# define new method
def get_size
# method implementation
length
end
end
Continue reading
8 comments | tags: class_eval, dsl, Java, mixin, module, reopen class, Ruby, stringutils | posted in Java, Ruby, TechKnow
Jan
10
2007
I attended last nights San Francisco Ruby group meet up held at CNET. The theme of last nights meeting was Lightning Talks and Mini Hack Session. I was only able to attend for the Lighting Talks.
Rich Collins started off the lightning talks with a presentation of his new Ruby on Rails plugin Simply Presentable. In the meeting Rich said that Simply Presentable is an alternative to Simply Helpful, and view helpers in general. Simply Presentable introduces Presenter classes in your Rails projects, in addition to the already existing Model, View, and Controller classes. The Presenter class knows how to render the model, an active record instance, based on its state such as is it a new record or an existing record in the database.
Continue reading
no comments | posted in Conference, Mac, Ruby, TechKnow
Oct
30
2006
For ease of use, I am making available my RubyConf 2006 Conference Notes as a single PDF. The notes are released as Creative Commons Attribution-ShareAlike, so do with them whatever you want.

Just as an appendix, here is a list of all the sessions I was able to take notes for.
Friday, October 20 2006
Welcome To RubyConf 2006
The History of Ruby – Funny look at Ruby’s beginnings.
Rubinius – Hardcore Ruby
Dynamic Graphics with Ruby – Kewl!
Life After mkmf
Iron Mongrel – Fuzzing – Zed is the man! Not ‘THAT Guy.’
Radiant – Content Management Simplified
Matz Roundtable
Continue reading
no comments | posted in Conference, Programming, Ruby, TechKnow
Oct
30
2006
I started to list the session that I liked the most and I soon noticed that I was listing the whole RubyConf schedule! I learned a lot from the all the speakers and from the questions of the audience. I also have to mention that RubyConf is a more intimate conference than say JavaOne. At JavaOne, you are easily lost amongst the 15,000 developers and and marketers in attendance. RubyConf 2006 had about 300 hard core Rubyist in attendance, and me as an observer. Nathanial Talbott, of Terralien, reminded the audience that the first RubyConf, back in 2001, had roughly 30 participants and perhaps one or two of those where paid ruby practitioners.
Oh, I forgot to mention some Rails tips that I received during breakfast of the last day of the conference. I had breakfast with some rails developers from BraveNet. I asked them if they give tell me the key hint or tip that a new rails developers should be aware of. I was told told to never ever use namespaces in models, and that I should seriously think about using namespaces in controllers. Another general rails tip was to use routes to make pretty urls, as opposed to namespace controllers.
RubyConf was a great experience and I can’t wait to next year!
Technorati Tags: ruby, rubyconf, rubyconf2006, rails, javaone
no comments | posted in Conference, Ruby, TechKnow
Oct
30
2006
For the last session of RubyConf 2006, John Lam gave a talk by the name “You got your Ruby in my CLR!” RubyCLR is “a high-performance Ruby to .NET bridge that allows seamless integration of CLR and Ruby objects in the same Win32 process.” RubyCLR started as a tradition. John has a three-year-old son and for his first birthday John wanted to give him something other than plastic toys. For his son’s first birthday, John wrote a python program. John said that this was a way for him to “hack on family time.” For his son’s second birthday, John wanted to write a Ruby program that interoperated with Microsoft/CLR libraries for a flash card like game.
John had some code samples of how of using RubyCLR to develop a Windows Forms application. RubyCLR is open to C# hacks, it allows inline C# code in Ruby files! RubyCLR makes .NET suck less. John also talked about another scenario for using RubyCLR in a .NET environment. He stated that XAML is just too verbose and that with RubyCLR developer can use the XML Builder approach to building Avalon UI applications.
If you want to adopt a technology like RubyCLR, or JRuby for that matter, John suggests that you introduce it in non-threating tasks such as testing or administrative scripting. Another interesting quote by John was when he said “everything in life is easy until you turn on security.” He made this comment when asked about how he deals with opening a Ruby class when it has passed the verifier. I am sure he will come up with an interesting solution to issues like security, especially now that John Lam has been hired by Microsoft to continue his work with RubyCLR.
Technorati Tags: ruby, rubyconf, rubyconf2006, rubyclr, .net, microsoft, c#
no comments | posted in Conference, Ruby, TechKnow