oh_my_method 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/README.md +1 -1
- data/lib/oh_my_method/hash.rb +18 -0
- data/lib/oh_my_method/numeric.rb +5 -0
- data/lib/oh_my_method/string.rb +16 -0
- data/lib/oh_my_method/version.rb +1 -1
- data/lib/oh_my_method.rb +2 -0
- data/spec/oh_my_method/hash_spec.rb +20 -0
- data/spec/oh_my_method/numeric_spec.rb +14 -0
- data/spec/oh_my_method/string_spec.rb +15 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9321e7f25194cbc6ffbb7f3963c28e0ae7070b11
|
4
|
+
data.tar.gz: ff5fa14f657300136508e7d47f40de0acc493397
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5bb3ed39d2c65e3a34321e56a632d73141b492de1d9c8a5db6737ed9f2163fcdd996e443951f4dbed42e83da29446c9d39778e27a21f89d62eb29c2eedd0062
|
7
|
+
data.tar.gz: 95e3c085a8b3b56d24592347772ee62ddb64e43f11110c831cd05392965b26d3618647055adc353d9605f2e9899d58f24f7b6cd50a0842b1588c97f046b0d6ab
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Hash
|
2
|
+
def to_obj
|
3
|
+
obj = Object.new
|
4
|
+
|
5
|
+
each_pair do |name, value|
|
6
|
+
name = name.to_sym
|
7
|
+
|
8
|
+
if value.is_a?(Hash)
|
9
|
+
obj.define_singleton_method(name){ value.to_obj }
|
10
|
+
else
|
11
|
+
obj.define_singleton_method(name){ value }
|
12
|
+
end
|
13
|
+
obj.define_singleton_method("#{name}="){|v| define_singleton_method(name){v} }
|
14
|
+
end
|
15
|
+
|
16
|
+
obj
|
17
|
+
end
|
18
|
+
end
|
data/lib/oh_my_method/string.rb
CHANGED
@@ -10,4 +10,20 @@ class String
|
|
10
10
|
def sum_digit
|
11
11
|
self.chars.map(&:to_i).inject(:+)
|
12
12
|
end
|
13
|
+
|
14
|
+
def first
|
15
|
+
self[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
def last
|
19
|
+
self[-1]
|
20
|
+
end
|
21
|
+
|
22
|
+
def shuffle
|
23
|
+
if RUBY_VERSION < "2.0"
|
24
|
+
self.split('').shuffle.join
|
25
|
+
else
|
26
|
+
self.chars.shuffle.join
|
27
|
+
end
|
28
|
+
end
|
13
29
|
end
|
data/lib/oh_my_method/version.rb
CHANGED
data/lib/oh_my_method.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Hash Class" do
|
4
|
+
it "#to_object" do
|
5
|
+
hash = { hoge: "hoge", "piyo" => "piyo", fuga: { one: 1 }}
|
6
|
+
color = { red: 254, green: 177, blue: 100 }.to_obj
|
7
|
+
obj = hash.to_obj
|
8
|
+
expect(obj.hoge).to eq "hoge"
|
9
|
+
expect(obj.piyo).to eq "piyo"
|
10
|
+
expect(obj.fuga.one).to eq 1
|
11
|
+
|
12
|
+
expect(color.red).to eq 254
|
13
|
+
expect(color.green).to eq 177
|
14
|
+
expect(color.blue).to eq 100
|
15
|
+
|
16
|
+
obj.hoge = "hello"
|
17
|
+
|
18
|
+
expect(obj.hoge).to eq "hello"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Numeric Class" do
|
4
|
+
it "#notzero?" do
|
5
|
+
expect(0.notzero?).to eq false
|
6
|
+
expect((0.0).notzero?).to eq false
|
7
|
+
expect(Complex(0).notzero?).to eq false
|
8
|
+
expect(Rational(0,4).notzero?).to eq false
|
9
|
+
expect(3.notzero?).to eq true
|
10
|
+
expect((3.0).notzero?).to eq true
|
11
|
+
expect(Rational(3,4).notzero?).to eq true
|
12
|
+
expect(Complex(0,4).notzero?).to eq true
|
13
|
+
end
|
14
|
+
end
|
@@ -20,4 +20,19 @@ describe "String Class" do
|
|
20
20
|
expect("12321".sum_digit).to eq 9
|
21
21
|
expect("123456789".sum_digit).to eq 45
|
22
22
|
end
|
23
|
+
|
24
|
+
it "#first" do
|
25
|
+
expect("Hello".first).to eq "H"
|
26
|
+
expect("".first).to eq nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#last" do
|
30
|
+
expect("Hello".last).to eq "o"
|
31
|
+
expect("".last).to eq nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "#shuffle" do
|
35
|
+
word = "Hello"
|
36
|
+
expect(word.shuffle.chars.sort).to eq word.chars.sort
|
37
|
+
end
|
23
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oh_my_method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- siman-man
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,11 +51,15 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/oh_my_method.rb
|
54
|
+
- lib/oh_my_method/hash.rb
|
54
55
|
- lib/oh_my_method/integer.rb
|
56
|
+
- lib/oh_my_method/numeric.rb
|
55
57
|
- lib/oh_my_method/string.rb
|
56
58
|
- lib/oh_my_method/version.rb
|
57
59
|
- oh_my_method.gemspec
|
60
|
+
- spec/oh_my_method/hash_spec.rb
|
58
61
|
- spec/oh_my_method/integer_spec.rb
|
62
|
+
- spec/oh_my_method/numeric_spec.rb
|
59
63
|
- spec/oh_my_method/string_spec.rb
|
60
64
|
- spec/spec_helper.rb
|
61
65
|
homepage: https://github.com/siman-man/oh_my_method
|
@@ -83,7 +87,9 @@ signing_key:
|
|
83
87
|
specification_version: 4
|
84
88
|
summary: Collection of we method.
|
85
89
|
test_files:
|
90
|
+
- spec/oh_my_method/hash_spec.rb
|
86
91
|
- spec/oh_my_method/integer_spec.rb
|
92
|
+
- spec/oh_my_method/numeric_spec.rb
|
87
93
|
- spec/oh_my_method/string_spec.rb
|
88
94
|
- spec/spec_helper.rb
|
89
95
|
has_rdoc:
|