Designed for productivity

I’ve written several helper methods to assist me throughout an application. I’m not fluent in the Ruby language, so these helper methods don’t always go perfect the first time. Usually they aren’t too complicated, though. What I’m finding is that each time I write one, I think, “I’m sure I’m not the only one who has done this.” And sure enough, I’m not. So much, in fact, that Ruby has very similar methods built right into the language. Things like strip_links and pluralize. Simple, but very handy. And perhaps most importantly, they’re time savers.

For instance, just recently I wrote a function to find all of the new line (\n) characters within the comments, and “gsub” them into line break tags. This is a simple function, obviously, but it still wasted my time because I later found out about simple_format which does that very thing. It will treat one \n as a break tag and two \n’s as a new paragraph. I know what you’re thinking, “Why aren’t you using Textile?” I don’t have an answer for that. I haven’t looked into it much, but I believe you simply pass the text to an instance of a new RedCloth object, and then convert it back using .to_html? I think I’m a little skeptical when it comes to installing plugins/gems since I often have trouble getting things of that nature to work correctly on Dreamhost. Then again, it’s often a more effective way for me to learn when something is broken. And I’m usually good at that. Anyway, the point is the Ruby language is brilliant and it really was designed for productivity.

Comments

01

Chris on Wed Aug 30 at 12:20PM

It was also designed for fun, and it excels at that wonderfully.

With regard to RedCloth/textile, there’s nothing to be afraid of. Dreamhost has the gem installed, but you can freeze the gem into your own code and then upload if you are really worried. It’s so ridiculously easy to post with, honestly. But, you use writeboard, so you should know ;-)

02

Chris on Wed Aug 30 at 12:22PM

By the way, have you used to_sentence? It’s another extremely handy helper.

03

Ryan on Wed Aug 30 at 01:19PM

Good call, I forgot to mention how fun it really is. And yes, I have used to_sentence – it’s very handy.

Have something to say?
Please rewrite the image text Are You Human? Hint: Are You Human? Formatting Tips

or

© 2009 Ryan Heath | Site Management A Ruby on Rails production.

Get in Touch