Skip to content

Commit c055ea1

Browse files
committed
Initial commit.
0 parents  commit c055ea1

20 files changed

Lines changed: 205 additions & 0 deletions

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.reap/digest
2+
.yardoc
3+
doc
4+
log
5+
pkg
6+
tmp
7+
web
8+
work/sandbox

.ruby

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
source:
3+
- var
4+
authors:
5+
- name: trans
6+
email: transfire@gmail.com
7+
copyrights:
8+
- holder: Rubyworks
9+
year: '2006'
10+
license: BSD-2-Clause
11+
replacements: []
12+
alternatives: []
13+
requirements:
14+
- name: detroit
15+
groups:
16+
- build
17+
development: true
18+
- name: reap
19+
groups:
20+
- build
21+
development: true
22+
- name: lemon
23+
groups:
24+
- test
25+
development: true
26+
- name: ae
27+
groups:
28+
- test
29+
development: true
30+
dependencies: []
31+
conflicts: []
32+
repositories:
33+
- uri: git://github.com/rubyworks/main_like_module.git
34+
scm: git
35+
name: upstream
36+
resources:
37+
home: http://rubyworks.github.com/main_like_module
38+
code: http://github.com/rubyworks/main_like_module
39+
bugs: http://github.com/rubyworks/main_like_module/issues
40+
mail: http://groups.google.com/groups/rubyworks-mailinglist
41+
extra: {}
42+
load_path:
43+
- lib
44+
revision: 0
45+
summary: Completing the Object class proxy of toplevel.
46+
title: Main Like Module
47+
version: 0.1.0
48+
name: main_like_module
49+
description: ! 'Main Like Module completes the toplevel proxy of
50+
51+
the Object class, making the toplevel behave just
52+
53+
as if it were a module context.'
54+
organization: Rubyworks
55+
date: '2011-12-19'

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
script: "bundle exec ruby-test -Ilib -Itest test_*.rb"
3+
rvm:
4+
- 1.8.7
5+
- 1.9.2
6+
- 1.9.3
7+
- ree
8+
- rbx-2.0
9+
- jruby
10+

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source :rubygems
2+
gemspec

MANIFEST

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!mast .ruby bin demo lib man qed spec test [A-Z]*.*
2+
.ruby
3+
lib/main_like_module.rb
4+
README.md

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Main Like Module
2+
3+
__DESCRIPTION__
4+
5+
Did you know `main`? Main is actually the special name Ruby gives
6+
to the toplevel object. This object is very special, it is actually
7+
in part a proxy object for the Object class itself. But it's only
8+
a partial implementation.
9+
10+
I have long argued that the toplevel object should be replaced with
11+
an self extended module, e.g.
12+
13+
module Toplevel
14+
extend self
15+
# ruby is excuted here
16+
end
17+
18+
This would have a couple of signifficant benefits. First, the toplevel
19+
would no longer polute every other object in the system. And second,
20+
the toplevel would be a fully operation module context.
21+
22+
Alas, so far, no avail. But there is alwasy hope. But in the mean time,
23+
we can at least support the second point mentioned by completing the
24+
proxy, making it emulate the Object class context in full. And that's
25+
exactly what Main Like Module does.
26+
27+
28+
__COPYRIGHTS__
29+
30+
Copyright (c) 2009 Rubyworks
31+
32+
Main as Module is distributable in accordance with the BSD-2-Clause license.
33+
34+
See COPYING.md for details.
35+

lib/main_like_module.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Main like Module
2+
#
3+
# Main, ie. the top-level object, is not fully in-sync with
4+
# Module. So, certain methods like #define_method do not work.
5+
# This library fixes this.
6+
#
7+
# Techinally it is this authors opinion that the top-level object
8+
# most likely would be better-off as a self-extended module, and
9+
# methods defined in it do not automatically get added to the
10+
# Object class.
11+
#
12+
# On the other hand. It is probably best to never use the toplevel
13+
# except as a jumping in point to youre own namespace.
14+
#
15+
# Note that none of this would be needed if Main were just a self extended
16+
# module.
17+
18+
def_meth = Proc.new do |m|
19+
if /=$/ =~ m.to_s
20+
eval <<-END
21+
def self.#{m}(arg)
22+
Object.class_eval do
23+
#{m}(arg)
24+
end
25+
end
26+
END
27+
else
28+
eval <<-END
29+
def self.#{m}( *args, &block )
30+
Object.class_eval do
31+
#{m}( *args, &block )
32+
end
33+
end
34+
END
35+
end
36+
end
37+
38+
public
39+
40+
(Module.public_instance_methods - public_methods).each do |m|
41+
next if m == "initialize"
42+
next if m =~ /^\W+$/
43+
def_meth[m]
44+
end
45+
46+
private
47+
48+
(Module.private_instance_methods - private_methods).each do |m|
49+
next if m == "initialize"
50+
next if m =~ /^\W+$/
51+
def_meth[m]
52+
end
53+
54+
protected
55+
56+
(Module.protected_instance_methods - protected_methods).each do |m|
57+
next if m == "initialize"
58+
next if m =~ /^\W+$/
59+
def_meth[m]
60+
end
61+
62+
# Copyright (c) 2006 Thomas Sawyer (Ruby License)

var/authors

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- trans <transfire@gmail.com>
3+

var/copyrights

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
- (c) 2006 Rubyworks (BSD-2-Clause)

var/description

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Main Like Module completes the toplevel proxy of
2+
the Object class, making the toplevel behave just
3+
as if it were a module context.

0 commit comments

Comments
 (0)