Top Level Namespace

Includes:
UtilityFunctions

Defined Under Namespace

Modules: ANSIColor, BBCode, BinaryReader, ByteOrder, CrossCase, DupReplaceSnapshotMixin, Enumerable, EnumerableArgs, Expirable, FamousOneLiners, Kernel, Lisp, Multiton, NilComparable, NotCopyable, ORMSupport, OpenStructable, PhysicalConstant, PromoteSelf, Uninheritable Classes: Array, BlankSlate, Class, Coroutine, CountingSemaphore, EnumeratedType, FileList, Fixnum, FloatString, Foo, Functor, HArray, Hash, Heap, IOReactor, IORedirect, Infinity, Integer, Interval, InvalidNackError, LRUCache, Method, Mock, Module, MyMock, NackClass, NilClass, Numeric, Object, Pool, Reference, SimpleStringIO, Snapshot, StaticHash, String, Struct, SuperStruct, SyncArray, SyncHash, TagIterator, Time, Timer, TokenParser, TracePoint, Tuple, ValueHolder, Version

Constant Summary collapse

K =

1.rb one-liners helper lib.

Kernel
O =
Object
C =
Class
INFINITY =

constant (for aleph=0)

Infinity.instance
Semaphore =
CountingSemaphore
CodePoint =

This is the same as a Binding. Not really needed, but I like consistency :)

Binding
OrderedHash =

Synonym

Hash::Ordered

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resc(str) ⇒ Object

class Parser::Registry



322
# File 'lib/mega/tokenparser.rb', line 322

def self.resc(str) ; Regexp.escape(str) ; end

Instance Method Details

#autoload_classesObject

– Note: The Fixnum constants can’t be autoloded. How to fix? ++



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mega.rb', line 9

def autoload_classes
  # built-in
  autoload( 'CGI', 'cgi' )
  autoload( 'FCGI', 'fcgi' )
  autoload( 'FileUtils', 'fileutils' )
  autoload( 'OpenStruct', 'ostruct' )
  # mega classes
  autoload( 'ANSICode', 'mega/ansicode' )
  autoload( 'BBCode', 'mega/bbcode' )
  autoload( 'BinaryReader', 'mega/binaryreader' )
  autoload( 'BlankSlate', 'mega/blankslate' )
  autoload( 'ByteOrder', 'mega/byteorder' )
  autoload( 'ClassMethods', 'mega/classmethods' )
  autoload( 'Coroutine', 'mega/coroutine' )
  autoload( 'CrossCase', 'mega/crosscase' )
  autoload( 'EnumerableArgs', 'mega/enumerable_args' )
  autoload( 'EnumeratedType', 'mega/enumerated_type' )
  autoload( 'FileList', 'mega/expirable' )
  autoload( 'FloatString', 'mega/floatstring' )
  autoload( 'Functor', 'mega/functor' )
  autoload( 'HArray', 'mega/floatstring' )
  autoload( 'Heap', 'mega/heap' )
  autoload( 'Infinity', 'mega/infinity' )
  autoload( 'Interval', 'mega/interval' )
  autoload( 'IOReactor', 'mega/ioreactor' )
  autoload( 'IORedirect', 'mega/ioredirect' )
  autoload( 'LRUCache', 'mega/lru_cache' )
  autoload( 'MethodProbe', 'mega/methodprobe' )
  autoload( 'Multiton', 'mega/multiton' )
  autoload( 'Nack', 'mega/nack' )
  autoload( 'NilComparable', 'mega/nilcomparable' )
  autoload( 'NotCopyable', 'mega/notcopyable' )
  autoload( 'OpenStructable', 'mega/ostructable' )
  autoload( 'OrderedHash', 'mega/ohash' )
  autoload( 'PhysicalConstant', 'mega/physical_const' )
  autoload( 'Pool', 'mega/pool' )
  autoload( 'PromoteSelf', 'mega/promoteself' )
  autoload( 'Reference', 'mega/reference' )
  autoload( 'Semaphore', 'mega/semaphore' )
  autoload( 'StackParser', 'mega/stackparser' )
  autoload( 'StaticHash', 'mega/statichash' )
  autoload( 'SuperStruct', 'mega/superstruct' )
  autoload( 'SyncHash', 'mega/synchash' )
  autoload( 'SyncArray', 'mega/syncarray' )
  autoload( 'SyncHash', 'mega/synchash' )
  autoload( 'TagIterator', 'mega/tagiter' )
  autoload( 'Timer', 'mega/timer' )
  autoload( 'TracePoint', 'mega/tracepoint' )
  autoload( 'Tuple', 'mega/tuple' )
  autoload( 'Uninheritable', 'mega/uninheritable' )
  autoload( 'Version', 'mega/version' )
end

#Mock(realclass) ⇒ Object

Factory method for creating semi-functional mock objects given the class which is to be mocked. It looks like a constant for purposes of syntactic sugar.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/mega/mock.rb', line 134

def Mock( realclass )

  mockclass = Class.new( Mock )

  mockclass.instance_eval do @mocked_class = realclass end

  # Provide an accessor to class instance var that holds the class
  # object we're faking
  class << mockclass
    # The actual class being mocked
    attr_reader :mocked_class

    # Propagate the mocked class ivar to derivatives so it can be
    # called like:
    #   class MockFoo < Mock( RealClass )
    def inherited( subclass )
      mc = self.mockedClass
      subclass.instance_eval do @mocked_class = mc end
    end
  end

  # Build method definitions for all the mocked class's instance
  # methods, as well as those given to it by its superclasses, since
  # we're not really inheriting from it.
  imethods = realclass.instance_methods(true).collect do |name|
    next if name =~ ::Mock::UnmockedMethods

    # Figure out the argument list
    arity = realclass.instance_method( name ).arity
    optargs = false

    if arity < 0
      optargs = true
      arity = (arity+1).abs
    end

    args = []
    arity.times do |n| args << "arg#{n+1}" end
    args << "*optargs" if optargs

    # Build a method definition. Some methods need special
    # declarations.
    argsj = args.join(',')
    case name.intern
    when :initialize
      "def initialize(#{argsj}) ; super ; end"
    else
      "def #{name}(#{argsj}) ; self.send(#{name},#{argsj}) ; end"
      #"def %s( %s ) ; self.__mockRegisterCall(%s) ; end" %
      #  [ name, argstr, [":#{name}", *args].join(',') ]
    end
  end

  # Now add the instance methods to the mockclass class
  mockclass.class_eval imethods.join( "\n" )

  return mockclass
end

#nail(arg) ⇒ Object

A private Object method which will raise a NackClass’ error.



114
115
116
117
118
119
120
# File 'lib/mega/nack.rb', line 114

def nail( arg )
  if NackClass === arg
    arg.raise_error
  else
    return arg
  end
end