Skip to content

Instantly share code, notes, and snippets.

@jendiamond
Last active April 19, 2016 21:42
Show Gist options
  • Select an option

  • Save jendiamond/27276392a19b908d7a385e0071ac1c9c to your computer and use it in GitHub Desktop.

Select an option

Save jendiamond/27276392a19b908d7a385e0071ac1c9c to your computer and use it in GitHub Desktop.
class House
  def recite
    (1..pieces.length).map {|i| line(i)}.join("\n")
  end

  def line(number)
    "This is %s.\n" % pieces.last(number).join(' ')
  end

  private

  def pieces
    [
      'the horse and the hound and the horn that belonged to',
      'the farmer sowing his corn that kept',
      'the rooster that crowed in the morn that woke',
      'the priest all shaven and shorn that married',
      'the man all tattered and torn that kissed',
      'the maiden all forlorn that milked',
      'the cow with the crumpled horn that tossed',
      'the dog that worried',
      'the cat that killed',
      'the rat that ate',
      'the malt that lay in',
      'the house that Jack built',
    ]
  end
end

https://www.codecademy.com/courses/ruby-beginner-en-Zjd2y/0/1

$VERBOSE = nil    # We'll explain this at the end of the lesson.
require 'prime'   # This is a module. We'll cover these soon!

def first_n_primes(n)

  unless n.is_a? Integer
    return "n must be an integer."
  end

  if n <= 0
    return "n must be greater than 0."
  end
  
  prime_array = [] if prime_array.nil?
  
  prime = Prime.new
  for num in (1..n)
    prime_array.push(prime.next)
  end
  return prime_array
end

first_n_primes(10)

http://ghendry.net/refactor.html

Kevin Rutherford on Refactoring "My guiding light is Kent Beck's rules of Simple Design

The code must first be correct (as defined by tests); then it should be a clear statement of the design (what J.B.Rainsberger calls "no bad names"); then it should contain no duplication (of text, of ideas, or of responsibility); and finally it must be the smallest code that meets all of the above. It's time to stop refactoring when the code makes a reasonable stab at meeting those goals, and when any further changes would add no further benefit."

http://www.sandimetz.com/blog/2014/05/28/betting-on-wrong

http://www.sandimetz.com/blog/2014/9/9/shape-at-the-bottom-of-all-things

Sandi Metz talks POODR with the Toronto Ruby Brigade (03/12/13) https://www.youtube.com/watch?v=pUzL16pfdKY

RailsConf 2014 - All the Little Things by Sandi Metz https://www.youtube.com/watch?v=8bZh5LMaSmE

POODR - Sandi Metz's OO Ruby Principles - by Chris McGrath https://www.youtube.com/watch?v=Om-nhDbnbVo

Solid Principles by Uncle Bob Martin https://www.youtube.com/watch?v=oar-T2KovwE

GORUCO 2009 - SOLID Object-Oriented Design by Sandi Metz https://www.youtube.com/watch?v=v-2yFMzxqwU

Hashrocket Lunch n' Learn with Sandi Metz - The Meta Talk https://www.youtube.com/watch?v=C192WT8knpI

refactoring https://infinum.co/the-capsized-eight/articles/best-ruby-on-rails-refactoring-talks

http://codon.com/refactoring-ruby-with-monads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment