Setting Defaults in Ruby

Ruby — squarism @ 11:52 pm


Let’s start out with a plain old method.

Now let’s un-hardcode that string in the puts by adding a parameter.

Great. We have a default String. But what about something more complex. What if we want a hash of options. Say we have a little piece of an IRC client.

Now a more complicated example. All we’re doing here is loading defaults from a YAML file and doing the same thing as before.

Go ahead and give it a try and play with it. It’s a good recipe with many uses.

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2013 SQUARISM | powered by WordPress with Barecity