This file contains 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 'mixico' | |
module Redirector | |
# @param [Object] target Target of the redirection. | |
# @param [Array<Symbol>] methods ([]) If empty, redirect all methods, otherwise only redirect named ones. | |
def self.create(target, *methods) | |
my_module = Module.new | |
if methods.empty? | |
# Equivalent to gen_eval, but won't crash and probably lower performance. |
This file contains 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 Fidgit | |
# Redirects methods to an object, but does not mask methods and ivars from the calling context. | |
module RedirectorMethods | |
# Evaluate a block accessing methods and ivars from the calling context, but calling methods (not ivars) on this | |
# object if they don't exist on the calling context. | |
def instance_methods_eval(&block) | |
raise ArgumentEror unless block_given? | |
context = eval('self', block.binding) |
This file contains 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
C:/Users/Spooner/RubymineProjects/fidgit/examples/scroll_window_example.rb:44: [BUG] Segmentation fault | |
ruby 1.9.2dev (2010-05-31) [i386-mingw32] | |
-- control frame ---------- | |
c:0008 p:---- s:0019 b:0019 l:000018 d:000018 CFUNC :(null) | |
c:0007 p:---- s:0017 b:0017 l:000016 d:000016 CFUNC :new | |
c:0006 p:0043 s:0014 b:0014 l:000013 d:000013 TOP C:/Users/Spooner/RubymineProjects/fidgit/examples/scroll_window_example.rb:44 | |
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH | |
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :load | |
c:0003 p:0051 s:0006 b:0006 l:000434 d:0006cc EVAL -e:1 |
This file contains 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
# encoding: ascii-8bit | |
# To put ö directly into a string, I need to set the encoding to ascii-8bit. | |
require 'gosu' | |
include Gosu | |
class Game < Window | |
def initialize | |
super 640, 480, false |
This file contains 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
class Base | |
def self.register_instances | |
@@instances ||= {} | |
@@instances[self] || = [] | |
@@subclass_instances ||= {} | |
@@subclass_instances[self] || = [] | |
end | |
register_instances |
This file contains 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
class Object | |
class << self | |
# @example | |
# before(:initialize) do | |
# log.debug "Initializing chicken" | |
# end | |
def before(method_name, &block) | |
raise "Requires block" unless block_given? | |
original = instance_method(method_name) |
This file contains 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
process_comment_markup = lambda do |comment, code_type| | |
if Pry.color | |
comment.gsub!(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, code_type).term } | |
{"(?:em|i)" => 32, "(?:strong|b)" => 34}.each_pair do |tag, color| | |
comment.gsub!(/<#{tag}>(?:\s*\n)?(.*?)\s*<\/#{tag}>/m) { console_colorize($1, color) } | |
end | |
{"\\+" => 34, "_" => 32}.each_pair do |tag, color| | |
comment.gsub!(/\B#{tag}[^\s]+?#{tag}\B/) { console_colorize($1, color) } | |
end | |
comment.gsub!(/((?:^[ \t]+.+(?:\n+|\Z)/) { CodeRay.scan($1, code_type).term } |
This file contains 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 'renet' | |
class Client | |
attr_reader :id, :server, :ip | |
def initialize(server, id, ip) | |
@server, @id, @ip = server, id, ip | |
end | |
def send_packet(data, channel=0, reliable=true) |
This file contains 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
Absorb | |
Aging | |
Anachronism | |
Big and Small | |
Broken Physics | |
Climbing | |
Colony | |
Colossal | |
Evolution | |
Girl Games |
This file contains 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
workmad3: Spooner: tbh, if you did pretty much exactly the same thing as I just did, but grabbed the stdout reference, and opened the file into the two ivars, it would work | |
[12:46] banisterfiend: sweet_horse = SweetHorse.new | |
[12:46] workmad3: banisterfiend: woo! infinite recursion! | |
[12:46] Spooner: Yeah workmad3's answer seems more sensible :) | |
[12:46] banisterfiend: workmad3: STDOUT.puts blah | |
[12:46] banisterfiend: ;) | |
[12:46] workmad3: ;) | |
[12:47] Spooner: Thanks. I'll probably do that then :) | |
[12:47] injekt: pretty sure stdout depends on a write method, banisterfiend | |
[12:47] workmad3: Spooner: banister's method is exactly the same as mine, but creates the puts method explicitly rather than hijacking method_missing |