string_plus 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -9
- data/lib/string_plus.rb +10 -0
- data/lib/string_plus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e72cee50eeed4fcfe0f1a2d5903030ddc923ab9e
|
4
|
+
data.tar.gz: c078be114ac0e278aa4c29ac8d84eb549b28981c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33daf1f78e882bd3286798e049dbadd14b76d5ee62f74ac0ee96c7abd3e95acb465f1f3a26248e3c5c7be4cb289d01dd66e5ce4c1e6dccd02e3e81991822c533
|
7
|
+
data.tar.gz: 4aca017a5b34c69fd952d3904e8933715a29e7481595808bb5cf3d67b4dc07075453d01331024f880b77eb097edda3680c2704f0dc7f0d2640c28edb17756d78
|
data/README.md
CHANGED
@@ -9,9 +9,10 @@ Some stuff I like on `String`s.
|
|
9
9
|
Convert a space/underscore-separated String into camel case.
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
require "string_plus"
|
13
|
-
|
14
|
-
|
12
|
+
require "string_plus"
|
13
|
+
|
14
|
+
"hello_cool_world".camelcase
|
15
|
+
# => "HelloCoolWorld"
|
15
16
|
```
|
16
17
|
|
17
18
|
### `#lcamelcase`
|
@@ -19,9 +20,10 @@ require "string_plus"
|
|
19
20
|
Convert a space/underscore-separated String into lower camel case.
|
20
21
|
|
21
22
|
```ruby
|
22
|
-
require "string_plus"
|
23
|
-
|
24
|
-
|
23
|
+
require "string_plus"
|
24
|
+
|
25
|
+
"hello_cool_world".lcamelcase
|
26
|
+
# => "helloCoolWorld"
|
25
27
|
```
|
26
28
|
|
27
29
|
|
@@ -35,11 +37,28 @@ Acknowledgments:
|
|
35
37
|
* You're not creating a Constant, but retrieving it. So, if it doesn't already exist, it will raise an error.
|
36
38
|
|
37
39
|
```ruby
|
38
|
-
require "string_plus"
|
39
|
-
|
40
|
-
|
40
|
+
require "string_plus"
|
41
|
+
|
42
|
+
"basic_object".constantize
|
43
|
+
# => BasicObject
|
41
44
|
```
|
42
45
|
|
46
|
+
It also accepts nested constants, separated by `-`
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require "string_plus"
|
50
|
+
|
51
|
+
module ExternalModule
|
52
|
+
class InternalClass
|
53
|
+
class InceptionedClass
|
54
|
+
class DreamInsideADreamInsideADream; end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
"external_module-internal_class-inceptioned_class-dream_inside_a_dream_inside_a_dream".constantize
|
60
|
+
# => ExternalModule::InternalClass::InceptionedClass::DreamInsideADreamInsideADream
|
61
|
+
```
|
43
62
|
|
44
63
|
## Installation
|
45
64
|
|
data/lib/string_plus.rb
CHANGED
@@ -20,6 +20,16 @@ module StringPlus
|
|
20
20
|
camelcase(false)
|
21
21
|
end
|
22
22
|
|
23
|
+
def underscore
|
24
|
+
res = ""
|
25
|
+
[nil, *self.each_char].each_cons(2) do |last, current|
|
26
|
+
res << "_" if current == current.upcase && last != nil
|
27
|
+
res << current.downcase
|
28
|
+
end
|
29
|
+
res
|
30
|
+
end
|
31
|
+
alias :snakecase :underscore
|
32
|
+
|
23
33
|
def constantize
|
24
34
|
c = self.split("-").map(&:camelcase).join("::")
|
25
35
|
Object.send(:const_get, c)
|
data/lib/string_plus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|