For programmers who are new to Object Oriented Programming, the ideas behind classical inheritance can take some getting used to. This article walks you through the syntax of defining class inheritance in Ruby with explanations of each OOP feature along the way. You will have created many inheriting classes and used them in Ruby code by the end of this exercise.
Create a new Ruby code file and copy the code examples into it as you go. Run the file with the provided driver code and read the output. Try writing your own driver code to try things out new concepts as they're introduced.
| # Sample implementation of quicksort and mergesort in ruby | |
| # Both algorithm sort in O(n * lg(n)) time | |
| # Quicksort works inplace, where mergesort works in a new array | |
| def quicksort(array, from=0, to=nil) | |
| if to == nil | |
| # Sort the whole array, by default | |
| to = array.count - 1 | |
| end |
| > nest = [1,2,3, {name: "Vish", address: ["123 fake add", "456 fake add", city: ["toronto", "north york"]]}, ["thingy", "thingy2"]] | |
| #=> [1, 2, 3, {:name=>"Vish", :address=>["123 fake add", "456 fake add", {:city=>["toronto", "north york"]}]}, ["thingy", "thingy2"]] | |
| > nest[3] | |
| #=> {:name=>"Vish", :address=>["123 fake add", "456 fake add", {:city=>["toronto", "north york"]}]} | |
| > nest[3][:address] | |
| #=> ["123 fake add", "456 fake add", {:city=>["toronto", "north york"]}] | |
| > nest[3][:address][2] |
This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.
###Array ####Definition:
- Stores data elements based on an sequential, most commonly 0 based, index.
- Based on tuples from set theory.
| CREATE/////////////////////////// | |
| CREATE TABLE student (id INTEGER PRIMARY KEY, first_name TEXT, last_name TEXT, age INT); | |
| .tables /* Shows the table created */ | |
| .schema /* Shows the schema used to create the table */ | |
| SELECT * FROM student; /* Show all rows in the student table */ |
| ActiveRecord cheat sheet / EXAMPLES | |
| INSTALL | |
| ======= | |
| $ gem install activerecord | |
| in GEMFILE: gem ‘activerecord’ | |
| REQUIRE | |
| ======= | |
| require ‘active_record’ |
Getting started:
Related tutorials:
- MySQL-CLI: https://www.youtube.com/playlist?list=PLfdtiltiRHWEw4-kRrh1ZZy_3OcQxTn7P
- Analyzing Business Metrics: https://www.codecademy.com/learn/sql-analyzing-business-metrics
