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
# Create test/unit test with testcase("xxx") { test("yyy") { ... } ... } notation. | |
# Out-dated considering things like Shoulda. | |
# (c)2003 Christian Neukirchen | |
# | |
# Has one small issue: | |
# There is no way to close off blocks from the outside scope. | |
# This can cause interference between separate tests. | |
# So while this works for simple cases, it may well run into | |
# problems with anything sizable. |
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
# Playing around with an idea for true public vs. private access. | |
# | |
# Y is a subclass of X. | |
# x is an instance of X (ie. a public interface) | |
# Likewise y is an instance of Y. | |
# | |
# y | |
# | | |
# V | |
# Y:private -> Y:protected -> Y:public x |
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
# Experimental library for safe fluent method chaining. | |
# (Interesting idea, but a Null class would be better.) | |
# | |
# person = "John Doe" | |
# def person.address = "123 West St." | |
# person.address.street #=> Error | |
# | |
# To avoid the error use #chain: | |
# | |
# person.chain.address.street.end #=> nil |
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
# Method Filter - Dynamically Privatize New Methods | |
# | |
# Since Ruby is very dynamic, methods added to Object will show | |
# up in the list of available methods of subclasses. If we are trying to privatize | |
# methods to get them out of the way for method_missing, then this could pose | |
# a problem. We handle this by defining hooks in Object, Kernel and Module | |
# that will hide any method so defined automatically. | |
# | |
# This is rather useless now that Ruby 1.9 provides BasicObject. |
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#clone_xxx methods. These methods make it easy to | |
# create new subsets (or sidesets) of current modules. | |
# However facets/module pseudo-traits methods are better. | |
class Module | |
# Returns an anonymous module with the specified methods | |
# of the receiving module renamed. | |
def clone_renaming( pairs ) | |
mod = self.dup |
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 Module | |
# Directive for making your functions faster by trading | |
# space for time. When you "memoize" a method/function | |
# its results are cached so that later calls with the | |
# same arguments returns results in the cache instead | |
# of recalculating them. | |
# | |
# class T | |
# def initialize(a) | |
# @a = a |
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 Kernel #:nodoc: | |
# Object#cache is essentially like Module#memoize except | |
# it can also be used on singleton/eigen methods. | |
# OTOH, memoize's implementation is arguably better for it's | |
# use of #bind instead of #alias. Eventually the two implmenations | |
# should be reconciled with a single implementation. | |
# | |
def cache m = nil | |
if m | |
(Module === self ? self : (class << self; self; end)).module_eval <<-code |
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 View < ::Wx::Frame | |
def initialize | |
super(nil, -1, "My Application", | |
:style => Wx::DEFAULT_FRAME_STYLE | Wx::TAB_TRAVERSAL, | |
:size => [800,600] | |
) | |
setup_controls | |
setup_events | |
end |
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
# Pool - Thread Safe Object Store | |
# Copyright (c) 2004 George Moschovitis | |
# | |
# TODO: Could use the SizedQueue/Queue? | |
require 'thread' | |
require 'monitor' | |
# Generalized object pool implementation. Implemented as a thread | |
# safe stack. Exclusive locking is needed both for push and pop. |
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 'anise' | |
require 'facets/functor' | |
# Roll base class. | |
class Role | |
def initialize(player) | |
@player = player | |
end | |
# should be public send ? | |
def method_missing(s, *a, &b) |