Skip to content

Instantly share code, notes, and snippets.

View radavis's full-sized avatar

Richard Davis radavis

View GitHub Profile
class Car
attr_reader :color, :owner, :cylinders
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
end
class Card
attr_reader :rank, :suit
def initalize(rank, suit)
@suit = suit
@rank = rank
end
end
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase
@contents = []
end
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase
@contents = []
end
class Circle
def initialize(radius)
@radius = radius
end
def diameter
2 * @radius
end
def circumference
salutations = [['Mr.', 'Mrs.'], 'Mrs.', ['Mr.', 'Mrs.'], ['Dr.'], 'Ms.']
first_names = ['John', 'Jane', 'Sam', 'Louise', 'Kyle']
last_names = ['Dillinger', 'Cook', 'Livingston', 'Levinger', 'Merlotte']
addresses = ['33 Foolish Lane, Boston, MA 02210',
'45 Cottage Way, Dartmouth, MA 02342',
"54 Sally's Court, Bridgewater, MA 02324",
'4534 Broadway, Boston, MA 02110',
'4231 Cynthina Drive, Raynham, MA 02767']
mail_list = []
class Animal
attr_reader :name
def initialize(name)
@name = name
end
def eat
3.times { puts "chomp" }
end
select * from tasks where title = "Buy milk";
#!/usr/bin/env ruby
# run via command line: ./anagrams.rb word
p ARGV[0].chars.to_a.permutation.map(&:join)
-- What 3 towns have the highest population of citizens that are 65 years and older?
select city, population_over_65_in_2005
from town_health_records
order by population_over_65_in_2005 desc
limit 3;
-- city population_over_65_in_2005
-- ---------- --------------------------
-- Boston 59950
-- Worcester 23062