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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6a3349cf27f8f96303f09d2e650b9b44b309751
4
- data.tar.gz: 731c8d9472584bd7670c57e9d6f403c2133b0e0d
3
+ metadata.gz: 9321e7f25194cbc6ffbb7f3963c28e0ae7070b11
4
+ data.tar.gz: ff5fa14f657300136508e7d47f40de0acc493397
5
5
  SHA512:
6
- metadata.gz: 2b72e363107442079ae5d25aa36d247569d09af35f479607f9318560fa8a5bfb775da1d1a136d92a64031a4fdda6832fe921795dac69402a5daaab32cda0e007
7
- data.tar.gz: 701bd55d3e947527f290e2beffdc80f5d85f8af938fd395a736a495f96d20fcf82eb67ac599250f38cc39c04bf93c353d2dd2e0201303f67e6a3a52c8d53673d
6
+ metadata.gz: b5bb3ed39d2c65e3a34321e56a632d73141b492de1d9c8a5db6737ed9f2163fcdd996e443951f4dbed42e83da29446c9d39778e27a21f89d62eb29c2eedd0062
7
+ data.tar.gz: 95e3c085a8b3b56d24592347772ee62ddb64e43f11110c831cd05392965b26d3618647055adc353d9605f2e9899d58f24f7b6cd50a0842b1588c97f046b0d6ab
data/.gitignore CHANGED
@@ -15,3 +15,11 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ # Ignore junk file
20
+ doc/
21
+ **/*.swp
22
+ *.swp
23
+ **/*~
24
+ *.*~
25
+ *~
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # OhMyMethod
1
+ # Oh My Method
2
2
 
3
3
  This gem is collection of we methods.
4
4
 
@@ -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
@@ -0,0 +1,5 @@
1
+ class Numeric
2
+ def notzero?
3
+ !self.zero?
4
+ end
5
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module OhMyMethod
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/oh_my_method.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require "oh_my_method/version"
2
+ require "oh_my_method/numeric"
2
3
  require "oh_my_method/integer"
3
4
  require "oh_my_method/string"
5
+ require "oh_my_method/hash"
@@ -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.5
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-02 00:00:00.000000000 Z
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: