CRUD with Active Record

Say you’re creating a blog. A blog has many posts, and a post belongs to a blog. I’ll use the “Post” class for these examples, however these can be substituted with any class name (capital and singular!). Create There’s essentially a couple of ways to create a new record. One way of doing it: p...
Read More

Inheritance with Ruby

Inheritance, in a nutshell, is exactly what it sounds like. There’s a “superclass”, which has all the basic functionality and attributes that everyone inheriting from it will have. There’s the inheritors, which will be able to obtain all the methods of their superclass simply by calling “super”. So basically when creating a superclass, you must always think that it has to be generic enough that many other classes can use it, and try to limit the things you put in it (attributes and methods) to things that will be shared by every other class.

Read More

Starting a RoR app – in 15 minutes

Creating a Rails app from scratch is pretty easy thanks to its awesome generators. This is assuming that all the installation is done.  This is all done through the handy ol’ command line. 1. Create a new app. rails new RailsAppName # This goes in CamelCase! This will create a bare app in the RailsAppName...
Read More

Blocks, Procs & Lambdas

Blocks A block is pretty straightforward. There’s the do … end block: If I’ve got an array of numbers: numbers = [1,2,3,4] numbers.map do |num| num * num end or the single-line curly braces block numbers.each { |num| num * num } Proc (procedure) This is kind of a “named” block that you can save...
Read More