mult 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +45 -0
- data/ext/mult/compat.h +27 -0
- data/ext/mult/extconf.rb +3 -0
- data/ext/mult/mult.c +79 -0
- data/lib/mult.rb +13 -0
- metadata +68 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/* Copyright (c) 2007 Scott Lembcke
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to deal
|
5
|
+
* in the Software without restriction, including without limitation the rights
|
6
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
* copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
* SOFTWARE.
|
20
|
+
*/
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rake/extensiontask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
|
6
|
+
MULT_VERSION = "0.1.2"
|
7
|
+
|
8
|
+
dlext = Config::CONFIG['DLEXT']
|
9
|
+
|
10
|
+
CLEAN.include("ext/**/*.#{dlext}", "ext/**/.log", "ext/**/.o", "ext/**/*~", "ext/**/*#*", "ext/**/.obj", "ext/**/.def", "ext/**/.pdb")
|
11
|
+
CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o", "doc/**")
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = "mult"
|
15
|
+
s.summary = "a few handy extensions to mess with ruby objects"
|
16
|
+
s.description = s.summary
|
17
|
+
s.version = MULT_VERSION
|
18
|
+
s.author = "John Mair (banisterfiend)"
|
19
|
+
s.email = 'jrmair@gmail.com'
|
20
|
+
s.date = Time.now.strftime '%Y-%m-%d'
|
21
|
+
s.require_path = 'lib'
|
22
|
+
s.homepage = "http://banisterfiend.wordpress.com"
|
23
|
+
s.platform = Gem::Platform::RUBY
|
24
|
+
s.extensions = FileList["ext/**/extconf.rb"]
|
25
|
+
s.has_rdoc = true
|
26
|
+
s.files = ["Rakefile", "README.rdoc", "LICENSE", "lib/mult.rb"] +
|
27
|
+
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
31
|
+
pkg.need_zip = false
|
32
|
+
pkg.need_tar = false
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::ExtensionTask.new('mult', spec) do |ext|
|
36
|
+
ext.config_script = 'extconf.rb'
|
37
|
+
ext.cross_compile = true
|
38
|
+
ext.cross_platform = 'i386-mswin32'
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::RDocTask.new do |rd|
|
42
|
+
rd.main = "README.rdoc"
|
43
|
+
rd.rdoc_files.include("README.rdoc", "ext/mult/*.c")
|
44
|
+
end
|
45
|
+
|
data/ext/mult/compat.h
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
/* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
|
2
|
+
|
3
|
+
#ifndef GUARD_COMPAT_H
|
4
|
+
#define GUARD_COMPAT_H
|
5
|
+
|
6
|
+
#include <ruby.h>
|
7
|
+
|
8
|
+
/* this is the test we use to identify ruby 1.9.1 */
|
9
|
+
|
10
|
+
/* commenting out this test because it doesn't seem to work in 1.8.7 */
|
11
|
+
/*
|
12
|
+
#ifdef RCLASS_M_TBL
|
13
|
+
# define RUBY_19
|
14
|
+
#endif
|
15
|
+
*/
|
16
|
+
|
17
|
+
/* macros for backwards compatibility with 1.8 */
|
18
|
+
#ifndef RCLASS_M_TBL
|
19
|
+
# define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
|
20
|
+
# define RCLASS_SUPER(c) (RCLASS(c)->super)
|
21
|
+
# define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
|
22
|
+
#endif
|
23
|
+
|
24
|
+
/* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
|
25
|
+
#define KLASS_OF(c) (RBASIC(c)->klass)
|
26
|
+
|
27
|
+
#endif
|
data/ext/mult/extconf.rb
ADDED
data/ext/mult/mult.c
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "compat.h"
|
3
|
+
|
4
|
+
|
5
|
+
/* return the actual class of an object */
|
6
|
+
static VALUE
|
7
|
+
get_class(VALUE self) {
|
8
|
+
|
9
|
+
return CLASS_OF(self);
|
10
|
+
}
|
11
|
+
|
12
|
+
/* set the class of an object */
|
13
|
+
static VALUE
|
14
|
+
set_class(VALUE self, VALUE klass) {
|
15
|
+
|
16
|
+
KLASS_OF(self) = klass;
|
17
|
+
|
18
|
+
return klass;
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
/* get the actual super class of an object */
|
23
|
+
static VALUE
|
24
|
+
get_super(VALUE self)
|
25
|
+
{
|
26
|
+
return RCLASS_SUPER(self);
|
27
|
+
}
|
28
|
+
|
29
|
+
/* set the super class of an object */
|
30
|
+
static VALUE
|
31
|
+
set_super(VALUE self, VALUE klass) {
|
32
|
+
|
33
|
+
RCLASS_SUPER(self) = klass;
|
34
|
+
|
35
|
+
return klass;
|
36
|
+
}
|
37
|
+
|
38
|
+
/* is the object a singleton class ? */
|
39
|
+
static VALUE
|
40
|
+
is_singleton(VALUE self, VALUE klass) {
|
41
|
+
|
42
|
+
return FL_TEST(self, FL_SINGLETON) ? Qtrue : Qfalse;
|
43
|
+
}
|
44
|
+
|
45
|
+
/* get the attached class if receiver is a singleton class */
|
46
|
+
static VALUE
|
47
|
+
get_attached(VALUE self)
|
48
|
+
{
|
49
|
+
if(FL_TEST(self, FL_SINGLETON))
|
50
|
+
return rb_iv_get(self, "__attached__");
|
51
|
+
else
|
52
|
+
return Qnil;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
/* set the attached class if receiver is a singleton class */
|
57
|
+
static VALUE
|
58
|
+
set_attached(VALUE self, VALUE klass) {
|
59
|
+
if(FL_TEST(self, FL_SINGLETON)) {
|
60
|
+
rb_iv_set(self, "__attached__", klass);
|
61
|
+
return self;
|
62
|
+
}
|
63
|
+
else
|
64
|
+
return Qnil;
|
65
|
+
}
|
66
|
+
|
67
|
+
void
|
68
|
+
Init_mult() {
|
69
|
+
rb_define_method(rb_cObject, "actual_class", get_class, 0);
|
70
|
+
rb_define_method(rb_cObject, "actual_class=", set_class, 1);
|
71
|
+
|
72
|
+
rb_define_method(rb_cClass, "actual_super", get_super, 0);
|
73
|
+
rb_define_method(rb_cClass, "actual_super=", set_super, 1);
|
74
|
+
|
75
|
+
rb_define_method(rb_cClass, "is_singleton?", is_singleton, 0);
|
76
|
+
|
77
|
+
rb_define_method(rb_cClass, "attached", get_attached, 0);
|
78
|
+
rb_define_method(rb_cClass, "attached=", set_attached, 1);
|
79
|
+
}
|
data/lib/mult.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
direc = File.dirname(__FILE__)
|
4
|
+
dlext = Config::CONFIG['DLEXT']
|
5
|
+
begin
|
6
|
+
if RUBY_VERSION && RUBY_VERSION =~ /1.9/
|
7
|
+
require "#{direc}/1.9/mult.#{dlext}"
|
8
|
+
else
|
9
|
+
require "#{direc}/1.8/mult.#{dlext}"
|
10
|
+
end
|
11
|
+
rescue LoadError => e
|
12
|
+
require "#{direc}/mult.#{dlext}"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mult
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- John Mair (banisterfiend)
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-06 00:00:00 +12:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: a few handy extensions to mess with ruby objects
|
22
|
+
email: jrmair@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions:
|
26
|
+
- ext/mult/extconf.rb
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- Rakefile
|
31
|
+
- README.rdoc
|
32
|
+
- LICENSE
|
33
|
+
- lib/mult.rb
|
34
|
+
- ext/mult/extconf.rb
|
35
|
+
- ext/mult/compat.h
|
36
|
+
- ext/mult/mult.c
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://banisterfiend.wordpress.com
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.6
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: a few handy extensions to mess with ruby objects
|
67
|
+
test_files: []
|
68
|
+
|