small 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/small.rb +1 -1
- data/lib/small/hash.rb +21 -4
- data/lib/small/object.rb +28 -0
- data/lib/small/string.rb +11 -0
- metadata +4 -3
data/README.md
CHANGED
@@ -108,7 +108,7 @@ Small collection of useful Ruby utilities
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
**Notes:**
|
111
|
+
**Notes:** some codes extracted from ActiveSupport, but some codes are modified
|
112
112
|
|
113
113
|
## Benchmark
|
114
114
|
|
data/lib/small.rb
CHANGED
data/lib/small/hash.rb
CHANGED
@@ -1,13 +1,30 @@
|
|
1
1
|
class Hash
|
2
2
|
|
3
|
-
def
|
4
|
-
|
3
|
+
def transform_keys
|
4
|
+
result = {}
|
5
|
+
keys.each {|key| result[(yield(key) rescue key)] = self[key] }
|
6
|
+
result
|
7
|
+
end
|
8
|
+
|
9
|
+
def transform_keys!
|
10
|
+
keys.each {|key| self[(yield(key) rescue key)] = delete(key)}
|
5
11
|
self
|
6
12
|
end
|
7
13
|
|
14
|
+
def stringify_keys
|
15
|
+
transform_keys(&:to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stringify_keys!
|
19
|
+
transform_keys!(&:to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def symbolize_keys
|
23
|
+
transform_keys(&:to_sym)
|
24
|
+
end
|
25
|
+
|
8
26
|
def symbolize_keys!
|
9
|
-
|
10
|
-
self
|
27
|
+
transform_keys!(&:to_sym)
|
11
28
|
end
|
12
29
|
|
13
30
|
def to_param
|
data/lib/small/object.rb
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
class Object
|
2
2
|
|
3
|
+
def string?
|
4
|
+
is_a?(String)
|
5
|
+
end
|
6
|
+
|
7
|
+
def integer?
|
8
|
+
is_a?(Integer)
|
9
|
+
end
|
10
|
+
|
11
|
+
def boolean?
|
12
|
+
is_a?(FalseClass) || is_a?(TrueClass)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixnum?
|
16
|
+
is_a?(Fixnum)
|
17
|
+
end
|
18
|
+
|
19
|
+
def numeric?
|
20
|
+
is_a?(Numeric)
|
21
|
+
end
|
22
|
+
|
23
|
+
def float?
|
24
|
+
is_a?(Float)
|
25
|
+
end
|
26
|
+
|
27
|
+
def proc?
|
28
|
+
is_a?(Proc)
|
29
|
+
end
|
30
|
+
|
3
31
|
def blank?
|
4
32
|
respond_to?(:empty?) ? empty? : !self
|
5
33
|
end
|
data/lib/small/string.rb
CHANGED
@@ -63,4 +63,15 @@ class String
|
|
63
63
|
require 'cgi' unless defined?(CGI)
|
64
64
|
CGI.unescape(self.to_s)
|
65
65
|
end
|
66
|
+
|
67
|
+
def html_escape
|
68
|
+
require 'erb' unless defined?(ERB::Util)
|
69
|
+
ERB::Util.html_escape(self.to_s)
|
70
|
+
end
|
71
|
+
|
72
|
+
def url_encode
|
73
|
+
require 'erb' unless defined?(ERB::Util)
|
74
|
+
ERB::Util.url_encode(self.to_s)
|
75
|
+
end
|
76
|
+
|
66
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: small
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: bryann83@gmail.com
|
@@ -49,8 +49,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
51
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.8.
|
52
|
+
rubygems_version: 1.8.23
|
53
53
|
signing_key:
|
54
54
|
specification_version: 3
|
55
55
|
summary: A small collection of useful Ruby utilities
|
56
56
|
test_files: []
|
57
|
+
has_rdoc:
|