Skip to content

Instantly share code, notes, and snippets.

View W-Mills's full-sized avatar

Will Mills W-Mills

View GitHub Profile
loop do
puts 'This is the outer loop.'
loop do
puts 'This is the inner loop.'
break
end
break
end
@W-Mills
W-Mills / twenty_one_final.rb
Last active August 27, 2018 18:25
Version 1.0.0 of text-based card game twenty one written in Ruby
SUITS = %w[C H D S]
SUITS_HASH = { 'C' => 'Clubs',
'H' => 'Hearts',
'D' => 'Diamonds',
'S' => 'Spades' }
DEALER_STOPS_AT = 17
BUST_IF_OVER = 21
def prompt(msg)
puts "==> #{msg}"
@W-Mills
W-Mills / citypark.rb
Last active December 16, 2018 19:57
Ruby OOP Basics article
#city_park.rb
class CityPark
attr_reader :name, :num_trees
def initialize(name, num_trees)
@name = name
@num_trees = num_trees
end
end
# greenspace.rb
class GreenSpace
attr_reader :name, :num_trees
def initialize(name, num_trees)
@name = name
@num_trees = num_trees
end
end
# recreation_centre.rb
module Swimmable
def swim
"Can swim here!"
end
end
class GreenSpace
attr_reader :name, :num_trees
# recreation_centre_expanded.rb
module Swimmable
def swim
"Can swim here!"
end
end
class GreenSpace
attr_accessor :name, :num_trees
# recreation_centre_last_example.rb
module Swimmable
def swim
"Can swim here!"
end
end
class GreenSpace
attr_accessor :name, :num_trees
@W-Mills
W-Mills / rubyPedacSnippet.js
Last active July 10, 2019 16:09
Ruby PEDAC Boilerplate Code Snippet for VSCode
{
"PEDAC": {
"scope": "ruby",
"prefix": "PEDAC",
"body": [
"=begin",
"Input: $1",
"Output: $2",
"\nProblem: \n\t- $3",
"\nClarifying Questions: \n\t- $4",
@W-Mills
W-Mills / javaScriptPedacSnippet.js
Created July 10, 2019 16:00
javaScript PEDAC Boilerplate for VSCode
{
"PEDAC": {
"scope": "javascript",
"prefix": "PEDAC",
"body": [
"/*",
"Input: $1",
"Output: $2",
"\nProblem: \n\t- $3",
@W-Mills
W-Mills / gist:b2ff8572aa5bee9cb791f7317d90282f
Created August 20, 2019 19:56
Clarifying this in javascript example 1
const foo = {
bar: 'baz',
getBar: function() { // assigned as a property on an object, getBar is a method
console.log(this.bar); // the value of this here is the direct-parent foo object context
},
};
foo.getBar() // logs 'baz'
const qux = foo.getBar; // assigning the function stored as the method getBar to the variable qux in the global scope