Skip to content

Instantly share code, notes, and snippets.

View PamBWillenz's full-sized avatar

PamBWillenz

View GitHub Profile
@PamBWillenz
PamBWillenz / And_ Or
Last active August 29, 2015 14:18
If Statements- Bloc Checkpoint
Specs
LOCK METHOD
The lock method should take four arguments:
def lock(a,b,c,d)
end
Each argument represents a number on a combination lock. The method will return "unlocked" or "locked", depending on whether the combination is correct. There are several combinations that are "correct".
The first number has to be a 3, 5, or 7
The second number has to be a 2
@PamBWillenz
PamBWillenz / Unexpected End
Created April 8, 2015 16:40
Debugging Code
def hello
"Hello World"
end
# describe "hello" do
# it "should return 'Hello World'" do
# expect(hello).to eq("Hello World")
# end
@PamBWillenz
PamBWillenz / Type Error
Last active August 29, 2015 14:18
Debugging Code
# a + " + " + b + " = " + (a + b)
def add(a,b)
"#{a} + #{b} = #{a+b}"
end
p add(1,2)
p add(5,7)
p add(10,12)
@PamBWillenz
PamBWillenz / No Name Error
Last active August 29, 2015 14:18
Debugging Code
def hello(first, last)
"Hello #{first} #{last}"
end
p hello("Steve", "Jobs")
Output
"Hello Steve Jobs"
# describe "hello" do
# it "should return 'Hello first name last name'" do
def hello(firstpresident1, lastpresident1)
"Hello #{firstpresident1} #{lastpresident1}"
end
def hello(firstpresident2, lastpresident2)
"Hello #{firstpresident2} #{lastpresident2}"
end
p hello("Abraham", "Lincoln")
p hello("George", "Washington")
Output
@PamBWillenz
PamBWillenz / No Method Error
Created April 8, 2015 13:21
Debugging Code
def hello(name1)
"Hello #{name1}"
end
def hello(name2)
"Hello #{name2}"
end
p hello("World")
p hello("Bob")
@PamBWillenz
PamBWillenz / RSpec code
Last active August 29, 2015 14:18
Reading RSpec Tests
describe "greet" do
it "says hello to someone" do
greeting = greet("Steve", "Jobs")
expect(greeting).to eq("Hello Steve Jobs.")
end
end
In order to make this test pass, you would implement the greet method as it's written below:
def greet(first, last)
@PamBWillenz
PamBWillenz / Math Operations
Last active August 29, 2015 14:18
Basic Ruby Syntax
Strings are declared by placing quotes around a word. "Hello World"
A command is needed to instruct the computer to do something with the "hello world" string. As we mentioned in the checkpoint, Ruby has a command called p which prints the value of an object - p "hello world"
Booleans, Symbols and Variables - primitive data, just strings and numbers
Underscores make variables easier to read. When underscores are used in this capacity it's known as using "snake-case". The other type of case that you'll see in programming is "camel-case", which looks like: ThisIsCamelCase.
Symbols are like strings, only with less functionality. A Symbol is designated with a colon (:) to the left of a word. Symbols can contain any alpha-numeric character, but they must start with a letter.