omega 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f1d688b94555b2803900676c622479138859691
4
+ data.tar.gz: 9a626a96365b8732700a791f70afb39c6a19f2e7
5
+ SHA512:
6
+ metadata.gz: 8d9b9cd568ff4392068eb4268e864dc8b540b22e878b5fc9b79b934d0c4f69c580fd8488d0fbe3c5477874c939dca6b922f79d63d5afcc32803a2cad37309ae4
7
+ data.tar.gz: a6bf605708ee998f654019f9d7343d6088c4e7eebb45e690e62e4ebd33a4bf1f50565f7b56bbe0c3f8248dc8e749fdf66b42e322ea2ee6186113881308168fd3
data/lib/omega.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'omega/math'
2
+ require 'omega/memoize'
3
+ require 'omega/meta'
4
+ require 'omega/descendants'
@@ -0,0 +1,9 @@
1
+ class Module
2
+ def descendants
3
+ ObjectSpace.each_object(Module).select {|m| m < self}
4
+ end
5
+
6
+ def class_descendants
7
+ ObjectSpace.each_object(Class).select {|c| c < self}
8
+ end
9
+ end
data/lib/omega/math.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Math
2
+ def self.fact n
3
+ raise TypeError, "#{n} is not an Integer" unless n.is_a? Integer
4
+ raise ArgumentError, "#{n} is negative" unless n >= 0
5
+ (1..n).inject(:*) || 1
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ class Module
2
+ def memoize n, *arr
3
+ meta = (class << self; self; end)
4
+ ([n] + arr).each do |m|
5
+ alias_method "memoized_#{m}", m
6
+ hash = Hash.new
7
+ define_method m do |*args|
8
+ if hash.include? args
9
+ hash[args]
10
+ else
11
+ v = hash[args] = method("memoized_#{m}".to_sym).call(*args)
12
+ v.freeze
13
+ v
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def cmemoize n, *m
20
+ meta = (class << self; self; end)
21
+ meta.memoize n, *m
22
+ end
23
+ end
24
+
25
+ # Let's make "main:Object" methods memoizable
26
+ def memoize n, *m
27
+ meta = (class << self; self; end)
28
+ meta.memoize n, *m
29
+ end
data/lib/omega/meta.rb ADDED
@@ -0,0 +1,6 @@
1
+ class Object
2
+ def metaclass
3
+ meta = (class << self; self; end)
4
+ meta
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omega
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nax
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Omega is a powerful set of extensions to the basic ruby standard.
15
+ email: max.bacoux@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/omega.rb
21
+ - lib/omega/descendants.rb
22
+ - lib/omega/math.rb
23
+ - lib/omega/memoize.rb
24
+ - lib/omega/meta.rb
25
+ homepage: http://rubygems.org/gems/omega
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A collection of libraries and extensions to the standard.
49
+ test_files: []