hash-dot 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hash-dot.rb +23 -6
  3. metadata +19 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0e7419a1a08a18fa9acc86a21a4ab01ddda41da
4
- data.tar.gz: 5ff826e3ddc5464517fb95a7c0b05724ed39176e
3
+ metadata.gz: 90e58f1d55d55c806e95fbec7f84516b5c4ce921
4
+ data.tar.gz: a9f908143fb0c1f7e5b872d49c8780bfa03102a2
5
5
  SHA512:
6
- metadata.gz: 2c48053d7d939dc666124131e573c9dec5c9adfe817f39744f59d78f13b9c1732a0b1cd6e24316fdad85fd07d7d1079d26959d7e992b33d44236e34926c50200
7
- data.tar.gz: 1a01c2b19a9c2a1f22a013e5ef120e523a4ff9f798cb800a43b2e4b31702c78fa8f66dea2ace7a00ebb64d36b74a078883253cd87ebea49e695d1f79d1663d89
6
+ metadata.gz: 338d9809ed8a8c3b1a052680f428e88d66f3cd2b843df0df8cacdf6bd67133d83640f967dff22da1563424aeb52944a455e5aec062b1356a824157a6e641f1f1
7
+ data.tar.gz: 4888b9668b1057de5e375bc93f608c6b26a9d096971611ff1475b1ae22542fa64966d39d9826ec617b0609bfcff19eb6d2e1b74c4395ac01854939ac567f3a26
@@ -1,12 +1,29 @@
1
1
  class Hash
2
+ def define_reader(key)
3
+ define_singleton_method(key.to_sym) do
4
+ if has_key?(key)
5
+ return self[key]
6
+ else
7
+ return self[key.to_sym]
8
+ end
9
+ end
10
+ end
11
+
12
+ def define_writer(key)
13
+ define_singleton_method(key.to_sym) do |value|
14
+ self[key[0..-2].to_sym] = value
15
+ end
16
+ end
17
+
2
18
  def method_missing(method, *opts)
3
19
  m = method.to_s
4
- msym = m.to_sym
5
- if self.has_key?(m)
6
- return self[m]
7
- elsif self.has_key?(msym)
8
- return self[msym]
20
+
21
+ if m[-1] == '='
22
+ define_writer(m)
23
+ return self.send(method, *opts)
24
+ else
25
+ define_reader(m)
26
+ return self.send(method, *opts)
9
27
  end
10
- super
11
28
  end
12
29
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-dot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
13
27
  description: Adds the JavaScript dot notation for accessing hash keys to ruby, so
14
28
  you can do my_hash.key1
15
29
  email: BenjaminPorter86@gmail.com
@@ -38,8 +52,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
52
  version: '0'
39
53
  requirements: []
40
54
  rubyforge_project:
41
- rubygems_version: 2.4.5
55
+ rubygems_version: 2.2.2
42
56
  signing_key:
43
57
  specification_version: 4
44
58
  summary: Adds the JavaScript hash syntax to ruby
45
59
  test_files: []
60
+ has_rdoc: