hash_brown 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .rvmrc
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hash_brown.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
4
+
5
+ task :default => :spec
6
+ task :test => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hash_brown/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hash_brown"
7
+ s.version = HashBrown::VERSION
8
+ s.authors = ["Ryland Herrick"]
9
+ s.email = ["ryland@bendyworks.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Turns Hash keys into methods}
12
+ s.description = %q{Now you don't need to fuss with brackets when using Hashes.
13
+ Abuses method_missing responsibly.}
14
+
15
+ s.rubyforge_project = "hash_brown"
16
+ s.add_development_dependency('rspec')
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
data/lib/hash_brown.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'hash_brown/version'
2
+
3
+ class Hash
4
+ def method_missing meth, *args, &block
5
+ return self[meth] if self.has_key? meth
6
+ return self[meth.to_s] if self.has_key? meth.to_s
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module HashBrown
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path('../../lib/hash_brown', __FILE__)
2
+
3
+ describe HashBrown do
4
+ let(:hash) {{ :key_sym => 'sym_val',
5
+ 'key_str' => 'str_val' }}
6
+
7
+ describe 'expected behavior' do
8
+ it 'preserves original behavior' do
9
+ hash[:key_sym].should == 'sym_val'
10
+ hash['key_str'].should == 'str_val'
11
+ end
12
+
13
+ context 'given no block' do
14
+
15
+ it 'raises a NoMethodError for an invalid key' do
16
+ lambda { hash.bogus_val }.should raise_error(NoMethodError)
17
+ end
18
+
19
+ it 'respects the default value' do
20
+ hash[:bogus_val].should be_nil
21
+ end
22
+ end
23
+
24
+ context 'given a default non-nil value' do
25
+ before { hash.default = 'default' }
26
+
27
+ it 'raises a NoMethodError for an invalid key' do
28
+ lambda { hash.bogus_val }.should raise_error(NoMethodError)
29
+ end
30
+
31
+ it 'respects the default value' do
32
+ hash[:bogus_val].should == 'default'
33
+ end
34
+ end
35
+ end
36
+
37
+ describe 'new behavior' do
38
+ describe 'methodized accessors' do
39
+ describe 'reader' do
40
+
41
+ it 'accesses by symbol' do
42
+ hash.key_sym.should == 'sym_val'
43
+ end
44
+
45
+ it 'accesses by string' do
46
+ hash.key_str.should == 'str_val'
47
+ end
48
+
49
+ context 'given comparable symbol and string keys' do
50
+
51
+ it 'accesses by symbol' do
52
+ hash['key_sym'] = 'unreachable'
53
+
54
+ hash.key_sym.should == hash[:key_sym]
55
+ hash.key_sym.should_not == hash['key_sym']
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'writer' do
61
+
62
+ xit 'assigns a symbol' do
63
+ hash.key_sym = 'new_val'
64
+ hash.key_sym.should == 'new_val'
65
+ end
66
+
67
+ xit 'assigns a string' do
68
+ hash.key_str = 'new_val'
69
+ hash.key_str.should == 'new_val'
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_brown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryland Herrick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-30 00:00:00.000000000 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &2168495840 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2168495840
26
+ description: ! "Now you don't need to fuss with brackets when using Hashes.\n Abuses
27
+ method_missing responsibly."
28
+ email:
29
+ - ryland@bendyworks.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Rakefile
37
+ - hash_brown.gemspec
38
+ - lib/hash_brown.rb
39
+ - lib/hash_brown/version.rb
40
+ - spec/hash_brown_spec.rb
41
+ has_rdoc: true
42
+ homepage: ''
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: hash_brown
62
+ rubygems_version: 1.6.2
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Turns Hash keys into methods
66
+ test_files:
67
+ - spec/hash_brown_spec.rb