Posts

Showing posts with the label Ruby

10 Things You Didn't Know Rails Could Do

Came across this great slide deck with some nice gems in it! I hope you find it useful! From:  http://speakerdeck.com/u/jeg2/p/10-things-you-didnt-know-rails-could-do Check out James Edwards Gray II on GitHub

Ruby Open Classes

Coming from the .NET world, if we ever wanted to improve a class (by adding to it's code), we really only had a couple of options: Subclass This is limiting because .NET is a single-inheritence model. This means a class can only be subclassed once. So if other developers want to add more functionality, you can end in an inheritance chain nightmare. Extension Methods Since .NET 3.0, we've had extension methods . These allow you to bolt your own methods on to a type - the one gotcha being that they must be static. This would mean that you could only get at any public members of the instance you are executed against. (I should note, these are not criticisms of the language. Just because I have jumped ship to Ruby, I still consider .NET to be a top-notch framework) Enter "Open Classes" In Ruby, we have what are called " Open Classes " - and they are pretty much what they say on the tin. Classes are open for extension and modification (yups, dire...

“Getting Started with Ruby” Kata

I have been having talks/ideas for some time about starting a bit of a affair with Ruby . As a .NET geek, you may be wondering “why?”. I don’t want to “go on” too much here, if you’re curious about these, please feel free to ask: It’s Designed for Programmers It’s Dynamic and Not JavaScript Rails Looks Interesting Massive Community Movement/Involvement Strong Open Source Community I got thinking. I want to get started, but have no idea where to begin. I make no claims that I am anything other than a complete n00b. So, I started feeling my way through the darkness and decided to try and formalise it into a kata that can be repeated. NOTE: This is totally a “bootstrapping” kata – if you have done anything beyond the basics with Ruby, this is of no good to you! The Kata Problem Create a simple class that returns a number formatted as a percentage. For whole numbers, “zero” decimal places should be removed, for fractions, they should be...