Skip to content

Instantly share code, notes, and snippets.

@philosodad
Created November 12, 2011 22:10
Show Gist options
  • Save philosodad/1361196 to your computer and use it in GitHub Desktop.
Save philosodad/1361196 to your computer and use it in GitHub Desktop.
7 languages Ruby Day 2
array2 = []
16.times{array2 << rand(100)}
[0,1,2,3].each{|index| 4.times{print array2[index], " ";index+=4};print "\n"}
def simple_grep file, pattern
File.open(file, "r") do |file|
while x = file.gets
puts x if x.match(pattern)
end
end
end
simple_grep ARGV[0], ARGV[1]
class Tree
attr_accessor :children, :node_name
def initialize opts
@node_name = opts.keys.first
@children = []
opts[@node_name].each{|k,v| x = {k=>v}; @children << Tree.new(x) }
end
def visit_all &block
visit &block
@children.each{|c| c.visit_all &block}
end
def visit &block
block.call self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment