This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module AntSim | |
| class World | |
| def initialize(size) | |
| @size = size | |
| @data = size.times.map { size.times.map { Cell.new(0,0,0) } } | |
| end | |
| def [](location) | |
| x,y = location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module AntSim | |
| class World | |
| def initialize(size) | |
| @size = size | |
| @data = size.times.map { size.times.map { Cell.new(0,0) } } | |
| end | |
| def [](location) | |
| x,y = location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 1.9.3 | |
| >> RUBY_VERSION | |
| => "1.9.3" | |
| >> Proc.new { |a,b| [a,b] }.call | |
| => [nil, nil] | |
| >> proc { |a,b| [a,b] }.call | |
| => [nil, nil] | |
| >> lambda { |a,b| [a,b] }.call | |
| ArgumentError: wrong number of arguments (0 for 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "celluloid" | |
| class Cell | |
| include Celluloid | |
| def initialize | |
| @pheremone = 0 | |
| # .. other variables | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Contractor | |
| FailedContract = Class.new(StandardError) | |
| class << self | |
| attr_accessor :enabled | |
| end | |
| def precondition(method, &block) | |
| constraint = Module.new do | |
| define_method method do |*a,&b| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Contractor | |
| def precondition(method, &block) | |
| constraint = Module.new do | |
| define_method method do |*a,&b| | |
| raise unless instance_exec(*a, b, &block) | |
| super(*a, &b) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Hi there! | |
| Back in August, we started working on switching our payment and email | |
| provider for Practicing Ruby. As part of that process, we disabled | |
| payments for new subscribers and re-subscribers temporarily so that we | |
| wouldn't send more people through the bad old process we used to have. | |
| Our records show that you are one of about 400 people who received a | |
| temporarily free account during this transition. | |
| I'm happy to say that as of today (November 15), we are now able to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ ruby -e "p ObjectSpace.each_object(Class).select { |e| e.ancestors.include?(Enumerable) }" | |
| [Enumerator::Generator, Enumerator, Struct::Tms, Dir, File, ARGF.class, IO, Range, Struct, Hash, Array] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "simple_uuid" | |
| class UUIDTracer < SimpleUUID::UUID | |
| def initialize(*a, &b) | |
| p [a, b] # replace this with a logger | |
| super | |
| end | |
| end | |
| SimpleUUID::UUID = UUIDTracer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| PATTERNS = { "gg" => "http://google.com/search?q=", | |
| "gmap" => "http://maps.google.com/maps?q=", | |
| "wp" => "http://en.wikipedia.org/?search=", | |
| "m" => "http://www.google.com/movies?near=" } | |
| app = lambda do |env| | |
| command, *args = URI.unescape(env["QUERY_STRING"]).gsub("+", " ").split |