Skip to content

Instantly share code, notes, and snippets.

@codetombomb
codetombomb / cat_spec.rb
Last active August 29, 2020 21:17
Alternate describe view
require "cat"
Rspec.describe("Cat"){ #examples }
@codetombomb
codetombomb / cat_spec.rb
Last active August 29, 2020 21:53
Initializing Cat instance with string name
require 'cat'
describe Cat do
it "is initialized with a name" do
cat = Cat.new("Wednesday")
expect(cat.name).to eq("Wednesday")
end
end
@codetombomb
codetombomb / expectations_examples.rb
Created August 29, 2020 22:16
Expectation Basic Structure
#We expect a thing that we set to match an outcome
expect(something).to matcher(outcome)
#We expect a thing that we set not to match an outcome
expect(something).not_to matcher(outcome)
expect(1<2).to be true
#what is really happening here is this:
expect(1<2).to(be(true))
@codetombomb
codetombomb / Car.rb
Last active September 16, 2020 04:27
Ruby Car Factory
class Car
attr_accessor :color, :year, :make, :model
def initialize(color, year, make, model)
# our instance variables are defined using a single @
@color = color
@year = year
@make = make
@model = model
end
@codetombomb
codetombomb / Car.rb
Last active September 16, 2020 04:42
Another Example for instance of self
class Car
attr_accessor :color, :year, :make, :model
def initialize(color, year, make, model)
@color = color
@year = year
@make = make
@model = model
end
def get_vin
@codetombomb
codetombomb / Car.rb
Last active September 16, 2020 04:47
Adding class methods
class Car
attr_accessor :color, :year, :make, :model
@@all = []
def initialize(color, year, make, model)
@color = color
@year = year
@make = make
@model = model
@@all << self
end
@codetombomb
codetombomb / functions.py
Last active September 23, 2020 00:18
Starting a Python function
# This is a comment. Comments start with the '#'
# Function one (for demonstration purposes)
def function_name(parameter):
#This is the functions body
#The body is defined by the indention at the begining of the line
print(parameter)
# Function two
def function_two():
@codetombomb
codetombomb / launch.json
Last active September 23, 2020 18:58
launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
@codetombomb
codetombomb / hello_world.py
Last active September 23, 2020 23:46
square funtion
def square(num):
answer = num * num
print(answer)
square(2)
square(4)
square(6)