Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
singleton Logger
def output
@output ||= STDOUT
end
attr_writer :output
def log(text)
output.puts(text)
end
186 XML.ri
187 Test.ri
191 RbConfig.ri
197 XMLEncoding_ja.ri
198 Data.ri
203 RDocTask.ri
204 DefaultKey.ri
210 GDBMError.ri
210 SDBMError.ri
211 GDBMFatalError.ri
seacreature:~$ rvm 1.8.7
seacreature:~$ irb
>> if true: true end
=> true
>> exit
seacreature:~$ rvm 1.9.2
seacreature:~$ irb
>> if true: true end
SyntaxError: (irb):1: syntax error, unexpected ':', expecting keyword_then or ';' or '\n'
if true: true end
@practicingruby
practicingruby / gist:1232567
Created September 21, 2011 16:34 — forked from stevemorris/gist:1232537
Circuitry
module Circuitry
extend self
def []=(name, definition)
circuits[name] = definition
end
def [](name)
circuits[name]
end
class MyEnumerator
include Enumerable
def initialize(target, *iterator)
@target = target
@iterator = iterator
end
def each(&block)
@target.send(*@iterator, &block)
class MyEnumerator
include Enumerable
def initialize(target, *iterator)
@target = target
@iterator = iterator
end
def each(&block)
class Bot
def initialize(parts)
add_parts(parts)
setup
end
def add_parts(parts)
parts.each { |part| extend(part) }
end
class Point
def initialize(x,y)
@x, @y = x, y
end
end
module Positionable
attr_accessor :map
def neighbors
# Is this a bug or just a behavior change? Know a workaround to get the 1.8 behavior in 1.9?
I would even be okay with explicitly having to define inspect as long as
I could get the original inspect behavior from Object back, but would prefer something simpler...
## Ruby 1.9.2
>> class A
>> def initialize(x,y,z)
>> @x, @y, @z = x,y,z
>> end