Skip to content

Instantly share code, notes, and snippets.

book('Charlie and the chocolate factory', 'Roald Dahl').
book('Boy', 'Roald Dahl').
book('Oliver Twist', 'Charles Dickens').
book('A Christmas Carol', 'Charles Dickens').
book('1984', 'George Orwell').
@jomontanari
jomontanari / 1-builder.io
Created November 23, 2011 04:12
IO Day 3
Builder := Object clone
Builder indent := 0
Builder writeIndent := method(for(i, 1, indent, " " print))
Builder forward := method(
self writeIndent
writeln("<", call message name, ">")
indent = indent +1
@jomontanari
jomontanari / 1-fibonacci.io
Created November 17, 2011 03:25
Seven Languages - IO Day 2
loop_fib := method(limit,
fib_sequence := list(1, 1)
i := 2
while (i <= limit, i = i + 1; fib_sequence append(fib_sequence last + fib_sequence at((fib_sequence size) - 2)))
fib_sequence at(limit-1)
)
loop_fib(1) println
loop_fib(4) println
@jomontanari
jomontanari / 1-typing.io
Created November 16, 2011 01:10
Seven Languages - IO Day 1
1 + 1 println
(1 + "one") println
@jomontanari
jomontanari / acts_as_csv.rb
Created November 5, 2011 22:51
Ruby - Day 3
class CsvRow
def initialize(headers, row)
@headers = headers
@row = row
end
def method_missing name
unless @headers.index(name.to_s).nil?
@row[@headers.index(name.to_s)]
end
@jomontanari
jomontanari / Access-files.rb
Created October 28, 2011 16:11
Ruby - Day 2
# With block - closes file automatically
File.open("test.txt") do |file|
puts file.readlines
end
# Without block
file = File.open("test.txt")
puts file.readlines
file.close
@jomontanari
jomontanari / homework.rb
Created October 28, 2011 12:53
Ruby - Day 1 (7l7w)
#Print the string Hello World
puts "Hello, World"
#Find the index of Ruby in "Hello, Ruby"
"Hello, Ruby".index("Ruby")
#Print your name 10 times
(1..10).each do
puts "Jo Cranford"
end
@jomontanari
jomontanari / guess-the-number.rb
Created October 28, 2011 12:47
Ruby - Day 1 - bonus problem (7l7w)
puts "What's the maximum number?"
max_num = gets().to_i
number_to_guess = rand(max_num + 1)
puts "Thinking of a number between 0 and #{max_num} ... OK."
guess = nil
while guess != number_to_guess do
puts "Please make a guess ..."
guess = gets().to_i