visionmedia-rext 0.0.3 → 0.0.4
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/History.rdoc +12 -0
- data/Manifest +13 -1
- data/README.rdoc +30 -4
- data/lib/rext/all.rb +4 -0
- data/lib/rext/array/helpers.rb +18 -0
- data/lib/rext/array.rb +6 -0
- data/lib/rext/compat/basic_object.rb +16 -0
- data/lib/rext/compat.rb +6 -0
- data/lib/rext/date/helpers.rb +2 -3
- data/lib/rext/enumerable/helpers.rb +2 -3
- data/lib/rext/integer.rb +0 -1
- data/lib/rext/numeric/bytes.rb +16 -0
- data/lib/rext/{integer → numeric}/time.rb +1 -1
- data/lib/rext/numeric.rb +7 -0
- data/lib/rext/object/metaclass.rb +27 -0
- data/lib/rext/object.rb +6 -0
- data/lib/rext/string/helpers.rb +19 -7
- data/lib/rext/version.rb +1 -1
- data/rext.gemspec +3 -3
- data/spec/array_spec.rb +24 -0
- data/spec/compat_spec.rb +28 -0
- data/spec/date_spec.rb +0 -2
- data/spec/hash_spec.rb +0 -2
- data/spec/integer_spec.rb +0 -18
- data/spec/module_spec.rb +0 -2
- data/spec/numeric_spec.rb +20 -0
- data/spec/object_spec.rb +42 -0
- data/spec/string_spec.rb +8 -0
- data/spec/time_spec.rb +0 -2
- metadata +23 -3
- data/Todo.rdoc +0 -15
data/History.rdoc
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
|
2
|
+
=== 0.0.4 / 2009-03-25
|
3
|
+
|
4
|
+
* Added Object#metaclass
|
5
|
+
* Added Object#meta_eval
|
6
|
+
* Added Object#meta_def
|
7
|
+
* Added BasicObject for Ruby < 1.9
|
8
|
+
* Added n param to String#first / last
|
9
|
+
* Added byte conversion 1.byte, 6.kilobytes etc
|
10
|
+
* Added form param to #to_time
|
11
|
+
* Added Array#from / to
|
12
|
+
* Moved time related methods from Integer to Numeric
|
13
|
+
|
2
14
|
=== 0.0.3 / 2009-03-25
|
3
15
|
|
4
16
|
* Added String#base64_encode
|
data/Manifest
CHANGED
@@ -2,6 +2,10 @@ benchmarks/enumerable.rb
|
|
2
2
|
benchmarks/proc.rb
|
3
3
|
History.rdoc
|
4
4
|
lib/rext/all.rb
|
5
|
+
lib/rext/array/helpers.rb
|
6
|
+
lib/rext/array.rb
|
7
|
+
lib/rext/compat/basic_object.rb
|
8
|
+
lib/rext/compat.rb
|
5
9
|
lib/rext/date/helpers.rb
|
6
10
|
lib/rext/date.rb
|
7
11
|
lib/rext/enumerable/helpers.rb
|
@@ -9,10 +13,14 @@ lib/rext/enumerable.rb
|
|
9
13
|
lib/rext/hash/helpers.rb
|
10
14
|
lib/rext/hash.rb
|
11
15
|
lib/rext/integer/helpers.rb
|
12
|
-
lib/rext/integer/time.rb
|
13
16
|
lib/rext/integer.rb
|
14
17
|
lib/rext/module/helpers.rb
|
15
18
|
lib/rext/module.rb
|
19
|
+
lib/rext/numeric/bytes.rb
|
20
|
+
lib/rext/numeric/time.rb
|
21
|
+
lib/rext/numeric.rb
|
22
|
+
lib/rext/object/metaclass.rb
|
23
|
+
lib/rext/object.rb
|
16
24
|
lib/rext/proc/helpers.rb
|
17
25
|
lib/rext/proc.rb
|
18
26
|
lib/rext/string/escape.rb
|
@@ -26,11 +34,15 @@ Manifest
|
|
26
34
|
Rakefile
|
27
35
|
README.rdoc
|
28
36
|
rext.gemspec
|
37
|
+
spec/array_spec.rb
|
38
|
+
spec/compat_spec.rb
|
29
39
|
spec/date_spec.rb
|
30
40
|
spec/enumerable_spec.rb
|
31
41
|
spec/hash_spec.rb
|
32
42
|
spec/integer_spec.rb
|
33
43
|
spec/module_spec.rb
|
44
|
+
spec/numeric_spec.rb
|
45
|
+
spec/object_spec.rb
|
34
46
|
spec/spec_helper.rb
|
35
47
|
spec/string_spec.rb
|
36
48
|
spec/time_spec.rb
|
data/README.rdoc
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
|
2
2
|
= Rext
|
3
3
|
|
4
|
-
|
5
|
-
however it is de-coupled and free to use within your own project.
|
6
|
-
|
7
|
-
|
4
|
+
Rext is primarily used for the Evolution CMS project, and its dependencies,
|
5
|
+
however it is de-coupled and free to use within your own project.
|
6
|
+
|
7
|
+
== Motivations
|
8
|
+
|
9
|
+
* ActiveSupport does not contain everything we need, and is messy IMO
|
10
|
+
* Very easy to cherry-pick what you need
|
11
|
+
* Provide better documentation
|
12
|
+
* Attention to quality and performance
|
13
|
+
* Abstraction of loosely coupled helpers used throughout Evolution and its sub-gems
|
8
14
|
|
9
15
|
== Usage
|
10
16
|
|
@@ -26,6 +32,11 @@ methods such as String#camelize etc.
|
|
26
32
|
|
27
33
|
Below are the methods currently provided by Rext.
|
28
34
|
|
35
|
+
* Object
|
36
|
+
- metaclass
|
37
|
+
- meta_def
|
38
|
+
- meta_eval
|
39
|
+
|
29
40
|
* String
|
30
41
|
- url_encode
|
31
42
|
- url_decode
|
@@ -34,6 +45,8 @@ Below are the methods currently provided by Rext.
|
|
34
45
|
- html_escape
|
35
46
|
- merge_word / add_class
|
36
47
|
- digitize
|
48
|
+
- camelize
|
49
|
+
- constantize
|
37
50
|
- wrap
|
38
51
|
- start_with?
|
39
52
|
- end_with?
|
@@ -47,6 +60,9 @@ Below are the methods currently provided by Rext.
|
|
47
60
|
|
48
61
|
* Integer
|
49
62
|
- ordanalize
|
63
|
+
|
64
|
+
* Numeric
|
65
|
+
- bytes, kilobytes, etc
|
50
66
|
- seconds, minutes, hours, days, ...
|
51
67
|
- to_seconds, to_minutes, to_hours, ...
|
52
68
|
- ago / before
|
@@ -72,6 +88,16 @@ Below are the methods currently provided by Rext.
|
|
72
88
|
- group_by
|
73
89
|
- every ( Copyright http://github.com/mynyml )
|
74
90
|
|
91
|
+
== Compatibility
|
92
|
+
|
93
|
+
Rext provides methods which support Ruby 1.8.x and 1.9.x, as
|
94
|
+
well as forward compatibility for features such as BasicObject.
|
95
|
+
|
96
|
+
== Contrib
|
97
|
+
|
98
|
+
Feel free to fork Rext on github, or submit a ticket:
|
99
|
+
http://visionmedia.lighthouseapp.com/projects/28074-rext/overview
|
100
|
+
|
75
101
|
== License
|
76
102
|
|
77
103
|
(The MIT License)
|
data/lib/rext/all.rb
CHANGED
@@ -4,10 +4,14 @@
|
|
4
4
|
#++
|
5
5
|
|
6
6
|
require 'rext'
|
7
|
+
require 'rext/object'
|
8
|
+
require 'rext/compat'
|
7
9
|
require 'rext/module'
|
8
10
|
require 'rext/proc'
|
9
11
|
require 'rext/enumerable'
|
12
|
+
require 'rext/array'
|
10
13
|
require 'rext/hash'
|
14
|
+
require 'rext/numeric'
|
11
15
|
require 'rext/integer'
|
12
16
|
require 'rext/string'
|
13
17
|
require 'rext/date'
|
data/lib/rext/array.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require 'rext/module/helpers'
|
3
|
+
|
4
|
+
class BasicObject
|
5
|
+
instance_methods.each { |m| undef_method m unless m.match(/^__/) }
|
6
|
+
end
|
7
|
+
|
8
|
+
module RemoveBasicObjectMethods
|
9
|
+
def method_added name
|
10
|
+
BasicObject.send :undef_method, name if self == Object
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Object.extend RemoveBasicObjectMethods
|
16
|
+
Kernel.extend RemoveBasicObjectMethods
|
data/lib/rext/compat.rb
ADDED
data/lib/rext/date/helpers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
require 'rext/compat/basic_object'
|
2
3
|
require 'rext/module/helpers'
|
3
4
|
require 'rext/proc/helpers'
|
4
5
|
|
@@ -19,9 +20,7 @@ module Enumerable
|
|
19
20
|
# * Enumerable#proxy
|
20
21
|
#
|
21
22
|
|
22
|
-
class Proxy
|
23
|
-
instance_methods.each { |m| undef_method m unless m.match(/^__/) }
|
24
|
-
|
23
|
+
class Proxy < BasicObject
|
25
24
|
def initialize object, meth
|
26
25
|
@object, @method = object, meth
|
27
26
|
end
|
data/lib/rext/integer.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
class Numeric
|
3
|
+
|
4
|
+
def bytes; self end
|
5
|
+
def kilobytes; self * 1024 end
|
6
|
+
def megabytes; self * 1024.kilobytes end
|
7
|
+
def gigabytes; self * 1024.megabytes end
|
8
|
+
def terabytes; self * 1024.gigabytes end
|
9
|
+
|
10
|
+
alias :byte :bytes
|
11
|
+
alias :kilobyte :kilobytes
|
12
|
+
alias :megabyte :megabytes
|
13
|
+
alias :gigabyte :gigabytes
|
14
|
+
alias :terabyte :terabytes
|
15
|
+
|
16
|
+
end
|
data/lib/rext/numeric.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
class Object
|
3
|
+
|
4
|
+
##
|
5
|
+
# Return the metaclass of this object.
|
6
|
+
|
7
|
+
def metaclass
|
8
|
+
class << self; self end
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Evaluate a +string+ or +block+ in context to this
|
13
|
+
# object metaclass.
|
14
|
+
|
15
|
+
def meta_eval string = nil, &block
|
16
|
+
return metaclass.class_eval(string) if string
|
17
|
+
metaclass.class_eval &block
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Define a singleton method.
|
22
|
+
|
23
|
+
def meta_def name, &block
|
24
|
+
meta_eval { define_method name, &block }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/rext/object.rb
ADDED
data/lib/rext/string/helpers.rb
CHANGED
@@ -176,17 +176,29 @@ class String
|
|
176
176
|
end
|
177
177
|
|
178
178
|
##
|
179
|
-
# First character.
|
179
|
+
# First +n+ character(s).
|
180
|
+
#
|
181
|
+
# === Examples
|
182
|
+
#
|
183
|
+
# 'foo'.first # => f
|
184
|
+
# 'foo'.first(2) # => fo
|
185
|
+
#
|
180
186
|
|
181
|
-
def first
|
182
|
-
self[0,
|
187
|
+
def first n = 1
|
188
|
+
self[0,n]
|
183
189
|
end
|
184
190
|
|
185
191
|
##
|
186
|
-
# Last character.
|
187
|
-
|
188
|
-
|
189
|
-
|
192
|
+
# Last +n+ character(s).
|
193
|
+
#
|
194
|
+
# === Examples
|
195
|
+
#
|
196
|
+
# 'bar'.last # => r
|
197
|
+
# 'bar'.last(2) # => ar
|
198
|
+
#
|
199
|
+
|
200
|
+
def last n = 1
|
201
|
+
self[-n, n]
|
190
202
|
end
|
191
203
|
|
192
204
|
end
|
data/lib/rext/version.rb
CHANGED
data/rext.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rext}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
9
9
|
s.date = %q{2009-03-25}
|
10
10
|
s.description = %q{Ruby extensions}
|
11
11
|
s.email = %q{tj@vision-media.ca}
|
12
|
-
s.extra_rdoc_files = ["lib/rext/all.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer/time.rb", "lib/rext/
|
13
|
-
s.files = ["benchmarks/enumerable.rb", "benchmarks/proc.rb", "History.rdoc", "lib/rext/all.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer/time.rb", "lib/rext/
|
12
|
+
s.extra_rdoc_files = ["lib/rext/all.rb", "lib/rext/array/helpers.rb", "lib/rext/array.rb", "lib/rext/compat/basic_object.rb", "lib/rext/compat.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/numeric.rb", "lib/rext/object/metaclass.rb", "lib/rext/object.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "README.rdoc", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
13
|
+
s.files = ["benchmarks/enumerable.rb", "benchmarks/proc.rb", "History.rdoc", "lib/rext/all.rb", "lib/rext/array/helpers.rb", "lib/rext/array.rb", "lib/rext/compat/basic_object.rb", "lib/rext/compat.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/numeric.rb", "lib/rext/object/metaclass.rb", "lib/rext/object.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "Manifest", "Rakefile", "README.rdoc", "rext.gemspec", "spec/array_spec.rb", "spec/compat_spec.rb", "spec/date_spec.rb", "spec/enumerable_spec.rb", "spec/hash_spec.rb", "spec/integer_spec.rb", "spec/module_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/time_spec.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "Todo.rdoc"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/visionmedia/rext}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rext", "--main", "README.rdoc"]
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'rext/array'
|
3
|
+
|
4
|
+
describe Array do
|
5
|
+
describe "helpers" do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@items = %w( some foo bar )
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#from" do
|
12
|
+
it "should return elements after the position specified" do
|
13
|
+
@items.from(1).should == %w( foo bar )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#to" do
|
18
|
+
it "should return elements up to position" do
|
19
|
+
@items.to(1).should == %w( some foo )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/spec/compat_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
require 'rext/compat'
|
3
|
+
|
4
|
+
describe Rext do
|
5
|
+
describe "compatibility" do
|
6
|
+
describe BasicObject do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@object = BasicObject.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have no methods" do
|
13
|
+
lambda { @object.send }.should raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should preserve __* methods" do
|
17
|
+
lambda { @object.__send__ }.should_not raise_error(NoMethodError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should now allow additional ancestor methods to be accessed" do
|
21
|
+
module Kernel; def foo; end end
|
22
|
+
class Object; def foo; end end
|
23
|
+
lambda { @object.foo }.should raise_error(NoMethodError)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/date_spec.rb
CHANGED
@@ -3,13 +3,11 @@ require 'rext/date'
|
|
3
3
|
|
4
4
|
describe Date do
|
5
5
|
describe "helpers" do
|
6
|
-
|
7
6
|
describe "#to_time" do
|
8
7
|
it "should convert to a Time instance" do
|
9
8
|
event = Date.parse('may 25th 1987')
|
10
9
|
event.to_time.should be_an_instance_of(Time)
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
15
13
|
end
|
data/spec/hash_spec.rb
CHANGED
@@ -3,7 +3,6 @@ require 'rext/hash'
|
|
3
3
|
|
4
4
|
describe Hash do
|
5
5
|
describe "helpers" do
|
6
|
-
|
7
6
|
describe "#delete_at" do
|
8
7
|
it "should delete several keys, returning their values when present" do
|
9
8
|
options = { :foo => 1, :bar => 2 }
|
@@ -13,6 +12,5 @@ describe Hash do
|
|
13
12
|
does_not_exist.should be_nil
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
end
|
data/spec/integer_spec.rb
CHANGED
@@ -15,22 +15,4 @@ describe Integer do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
describe "time" do
|
20
|
-
|
21
|
-
describe "#ago / #before" do
|
22
|
-
it "should return the distance in time before now, or specified time" do
|
23
|
-
event = Time.mktime 1987, 5, 25
|
24
|
-
15.days.before(event).should == Time.mktime(1987, 5, 10)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#since / #from_now" do
|
29
|
-
it "should return the distance in time from now, or specified time" do
|
30
|
-
event = Time.mktime 1987, 5, 25
|
31
|
-
5.days.since(event).should == Time.mktime(1987, 5, 30)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
18
|
end
|
data/spec/module_spec.rb
CHANGED
@@ -3,7 +3,6 @@ require 'rext/module'
|
|
3
3
|
|
4
4
|
describe Module do
|
5
5
|
describe "helpers" do
|
6
|
-
|
7
6
|
describe "#chain" do
|
8
7
|
it "should allow chaining via super" do
|
9
8
|
class Foo
|
@@ -33,6 +32,5 @@ describe Module do
|
|
33
32
|
lambda { Foo.new.does_not_exist }.should raise_error(NoMethodError)
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
36
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'rext/numeric'
|
3
|
+
|
4
|
+
describe Numeric do
|
5
|
+
describe "time" do
|
6
|
+
describe "#ago / #before" do
|
7
|
+
it "should return the distance in time before now, or specified time" do
|
8
|
+
event = Time.mktime 1987, 5, 25
|
9
|
+
15.days.before(event).should == Time.mktime(1987, 5, 10)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#since / #from_now" do
|
14
|
+
it "should return the distance in time from now, or specified time" do
|
15
|
+
event = Time.mktime 1987, 5, 25
|
16
|
+
5.days.since(event).should == Time.mktime(1987, 5, 30)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
require 'rext/object'
|
3
|
+
|
4
|
+
describe Object do
|
5
|
+
describe "metaclass" do
|
6
|
+
describe "#metaclass" do
|
7
|
+
it "should return the anonymous 'virtual' class" do
|
8
|
+
'foo'.metaclass.should be_an_instance_of(Class)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#meta_eval" do
|
13
|
+
it "should evaluate a block in context to the metaclass" do
|
14
|
+
object = 'foo'
|
15
|
+
object.meta_eval do
|
16
|
+
define_method :foo do
|
17
|
+
'bar'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
object.foo.should == 'bar'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept a string to be evaluated" do
|
24
|
+
object = 'foo'
|
25
|
+
object.meta_eval <<-EOF
|
26
|
+
def foo
|
27
|
+
'bar'
|
28
|
+
end
|
29
|
+
EOF
|
30
|
+
object.foo.should == 'bar'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#meta_def" do
|
35
|
+
it "should define a method within the metaclass" do
|
36
|
+
object = 'foo'
|
37
|
+
object.meta_def(:foo) { |*args| "bar #{ args.join(', ') }" }
|
38
|
+
object.foo(1,2,3).should == 'bar 1, 2, 3'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/string_spec.rb
CHANGED
@@ -89,12 +89,20 @@ describe String do
|
|
89
89
|
it "should return the first character" do
|
90
90
|
'foo'.first.should == 'f'
|
91
91
|
end
|
92
|
+
|
93
|
+
it "should return n number of charcters" do
|
94
|
+
'foo'.first(2).should == 'fo'
|
95
|
+
end
|
92
96
|
end
|
93
97
|
|
94
98
|
describe "#last" do
|
95
99
|
it "should return the last character" do
|
96
100
|
'bar'.last.should == 'r'
|
97
101
|
end
|
102
|
+
|
103
|
+
it "should return the last n number of characters" do
|
104
|
+
'bar'.last(2).should == 'ar'
|
105
|
+
end
|
98
106
|
end
|
99
107
|
|
100
108
|
describe "#camelize" do
|
data/spec/time_spec.rb
CHANGED
@@ -3,7 +3,6 @@ require 'rext/time'
|
|
3
3
|
|
4
4
|
describe Time do
|
5
5
|
describe "helpers" do
|
6
|
-
|
7
6
|
describe "#in_words_since" do
|
8
7
|
it "should convert time lost to words" do
|
9
8
|
event = Time.now - 5.seconds
|
@@ -18,6 +17,5 @@ describe Time do
|
|
18
17
|
event.in_words_since_now.should == 'hundreds of years'
|
19
18
|
end
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-rext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -21,6 +21,10 @@ extensions: []
|
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- lib/rext/all.rb
|
24
|
+
- lib/rext/array/helpers.rb
|
25
|
+
- lib/rext/array.rb
|
26
|
+
- lib/rext/compat/basic_object.rb
|
27
|
+
- lib/rext/compat.rb
|
24
28
|
- lib/rext/date/helpers.rb
|
25
29
|
- lib/rext/date.rb
|
26
30
|
- lib/rext/enumerable/helpers.rb
|
@@ -28,10 +32,14 @@ extra_rdoc_files:
|
|
28
32
|
- lib/rext/hash/helpers.rb
|
29
33
|
- lib/rext/hash.rb
|
30
34
|
- lib/rext/integer/helpers.rb
|
31
|
-
- lib/rext/integer/time.rb
|
32
35
|
- lib/rext/integer.rb
|
33
36
|
- lib/rext/module/helpers.rb
|
34
37
|
- lib/rext/module.rb
|
38
|
+
- lib/rext/numeric/bytes.rb
|
39
|
+
- lib/rext/numeric/time.rb
|
40
|
+
- lib/rext/numeric.rb
|
41
|
+
- lib/rext/object/metaclass.rb
|
42
|
+
- lib/rext/object.rb
|
35
43
|
- lib/rext/proc/helpers.rb
|
36
44
|
- lib/rext/proc.rb
|
37
45
|
- lib/rext/string/escape.rb
|
@@ -51,6 +59,10 @@ files:
|
|
51
59
|
- benchmarks/proc.rb
|
52
60
|
- History.rdoc
|
53
61
|
- lib/rext/all.rb
|
62
|
+
- lib/rext/array/helpers.rb
|
63
|
+
- lib/rext/array.rb
|
64
|
+
- lib/rext/compat/basic_object.rb
|
65
|
+
- lib/rext/compat.rb
|
54
66
|
- lib/rext/date/helpers.rb
|
55
67
|
- lib/rext/date.rb
|
56
68
|
- lib/rext/enumerable/helpers.rb
|
@@ -58,10 +70,14 @@ files:
|
|
58
70
|
- lib/rext/hash/helpers.rb
|
59
71
|
- lib/rext/hash.rb
|
60
72
|
- lib/rext/integer/helpers.rb
|
61
|
-
- lib/rext/integer/time.rb
|
62
73
|
- lib/rext/integer.rb
|
63
74
|
- lib/rext/module/helpers.rb
|
64
75
|
- lib/rext/module.rb
|
76
|
+
- lib/rext/numeric/bytes.rb
|
77
|
+
- lib/rext/numeric/time.rb
|
78
|
+
- lib/rext/numeric.rb
|
79
|
+
- lib/rext/object/metaclass.rb
|
80
|
+
- lib/rext/object.rb
|
65
81
|
- lib/rext/proc/helpers.rb
|
66
82
|
- lib/rext/proc.rb
|
67
83
|
- lib/rext/string/escape.rb
|
@@ -75,11 +91,15 @@ files:
|
|
75
91
|
- Rakefile
|
76
92
|
- README.rdoc
|
77
93
|
- rext.gemspec
|
94
|
+
- spec/array_spec.rb
|
95
|
+
- spec/compat_spec.rb
|
78
96
|
- spec/date_spec.rb
|
79
97
|
- spec/enumerable_spec.rb
|
80
98
|
- spec/hash_spec.rb
|
81
99
|
- spec/integer_spec.rb
|
82
100
|
- spec/module_spec.rb
|
101
|
+
- spec/numeric_spec.rb
|
102
|
+
- spec/object_spec.rb
|
83
103
|
- spec/spec_helper.rb
|
84
104
|
- spec/string_spec.rb
|
85
105
|
- spec/time_spec.rb
|
data/Todo.rdoc
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
|
2
|
-
== Major:
|
3
|
-
|
4
|
-
* in_words_since should == to_words_since?
|
5
|
-
* Hash.new { |h,k| h[k.to_s] if k.is_a? Symbol }
|
6
|
-
* best method for allowing map and others to utilize instance_eval and Proxy
|
7
|
-
* move time stuff to Numeric not Integer
|
8
|
-
|
9
|
-
== Minor:
|
10
|
-
|
11
|
-
* Nothing
|
12
|
-
|
13
|
-
== Brainstorming:
|
14
|
-
|
15
|
-
* Nothing
|