ccalc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/ccalc/ccalc.c +44 -0
- data/ext/ccalc/extconf.rb +2 -0
- data/lib/ccalc.rb +1 -0
- metadata +48 -0
data/ext/ccalc/ccalc.c
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
static VALUE t_init(VALUE self)
|
4
|
+
{
|
5
|
+
VALUE arr = rb_ary_new();
|
6
|
+
rb_iv_set(self, "@nums", arr);
|
7
|
+
return self;
|
8
|
+
}
|
9
|
+
|
10
|
+
static VALUE t_get(VALUE self, VALUE obj)
|
11
|
+
{
|
12
|
+
VALUE arr;
|
13
|
+
arr = rb_iv_get(self, "@nums");
|
14
|
+
rb_funcall(arr, rb_intern("push"), 1, obj);
|
15
|
+
return arr;
|
16
|
+
}
|
17
|
+
|
18
|
+
VALUE calculate(VALUE self, const char* sym)
|
19
|
+
{
|
20
|
+
VALUE arr = rb_iv_get(self, "@nums");
|
21
|
+
VALUE result = rb_funcall(arr, rb_intern("inject"), 1, ID2SYM(rb_intern(sym)));
|
22
|
+
rb_funcall(arr, rb_intern("clear"), 0);
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE t_plus(VALUE self)
|
27
|
+
{
|
28
|
+
return calculate(self, "+");
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE t_minus(VALUE self)
|
32
|
+
{
|
33
|
+
return calculate(self, "-");
|
34
|
+
}
|
35
|
+
|
36
|
+
void Init_ccalc()
|
37
|
+
{
|
38
|
+
VALUE cCalc;
|
39
|
+
cCalc = rb_define_class("Calc", rb_cObject);
|
40
|
+
rb_define_method(cCalc, "initialize", t_init, 0);
|
41
|
+
rb_define_method(cCalc, "get", t_get, 1);
|
42
|
+
rb_define_method(cCalc, "plus", t_plus, 0);
|
43
|
+
rb_define_method(cCalc, "minus", t_minus, 0);
|
44
|
+
}
|
data/lib/ccalc.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ccalc/ccalc'
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ccalc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicklasos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-04 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Dont's use it! It's a trap!
|
15
|
+
email: nicklasos@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/ccalc/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/ccalc.rb
|
22
|
+
- ext/ccalc/ccalc.c
|
23
|
+
- ext/ccalc/extconf.rb
|
24
|
+
homepage: http://rubygems.org/gems/ccalc
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.7.2
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Ccala!
|
48
|
+
test_files: []
|