Skip to content

Instantly share code, notes, and snippets.

@ogryzek
ogryzek / ruby_fee_struct.rb
Last active August 29, 2015 13:56
ruby Struct
Fee = Struct.new(:percentage, :max, :min)
# # equivalent to
# class Fee
# attr_accessor :percentage, :max, :min
# def initialize(percentage, max, min)
# self.percentage = percentage
# self.max = max
# self.min = min
# end
@ogryzek
ogryzek / homepage_controller_spec.rb
Last active August 29, 2015 13:56
rspec Homepage Features, Controller, Model examples
require 'spec_helper'
describe HomepageController do
describe "#index" do
it "is successful" do
get :index
expect(response).to be_success
end
end
@ogryzek
ogryzek / social_meta.html
Created February 22, 2014 18:47
Social media meta tags reference: Thanks to https://twitter.com/j_holtslander
<html>
<head>
<title>__________</title>
<!--[if lt IE 9]>
<script src="https://raw.github.com/aFarkas/html5shiv/master/src/html5shiv.js"></script>
<![endif]-->
<meta charset="utf-8">
<meta name="robots" content="noarchive"> <!-- Noarchive will prevent Google caching the page. -->
<meta name="keywords" data-page-subject="true" content="keyword,keyword,keyword,keyword,keyword,keyword,keyword" /> <!-- Relevant Keywords -->
<link rel="shortcut icon" href="favicon.ico">
@ogryzek
ogryzek / procs_and_lambdas.rb
Created February 26, 2014 05:27
Ruby Procs and Lambdas
# What's the difference between procs and lambdas?
#
# To really understand the difference, put it to use.
# irb is great for this.
# In irb, instantiate a Lambda and a Proc
l = lambda {|x, y| x.times {puts y}}
p = Proc.new {|x, y| x.times {puts y}}
# See that they are both of the same class
@ogryzek
ogryzek / _option_fields.html.haml
Last active August 29, 2015 13:56
accepts_nested_attributes
%fieldset.answer
= f.label :title
= f.text_field :title
= f.label :body
= f.text_field :body
= f.check_box :_destroy
= f.label :_destroy
%br
@ogryzek
ogryzek / intro_to_ruby.md
Last active August 29, 2015 13:57
Intro to Ruby

Intro to Ruby

IRB
Open up the terminal and in bash type

ruby -v

Open up an Interactive Ruby Shell

irb

Week 1: Homework

Ruby Basics

1.) Ask user for a number then print out the number multiplied by 5 and then the same number added to itself

# Ask user for a number then print out the number multiplied by 5 and then the same number added to itself
puts "enter a num"
answer = gets.chomp.to_i
puts "The number: #{answer} The number multiplied by 5: #{(answer*5)+answer}"

#Data Structures

Arrays | Hashes

Arrays

In Ruby, we define an aray simply using square brackets []

a = [1, 59, "Hey", "Yo", 200]
a[2]                  # "Hey"

You can put anything inside an array

Classes & Objects

Before object oriented programming, there was what's called 'Procedural Programming'. If I wanted to describe the mundane takss of my day to day routine, I could do so using procedures, such as "I wake up. I brush my teeth, etc."

However, we as humans tend to think of everything as an object. This is why languages like Ruby take objects to the extreme by making everything objects. Object oriented programming is good, because it makes thing easier to understand, and easier to extend. I can just include a library and have access to many more objects and methods.

I get into a car, which is an object. I turn on the car, which is a method on the object. Object interacting with each other is what OOP is all about.

Most modern languages are object oriented. Php, Java, Scala, etc.

Some Differences between a Class and an Object