subtle 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/lib/subtle/array_to_objects.rb +4 -4
- data/lib/subtle/version.rb +1 -1
- data/spec/subtle/array_to_object_spec.rb +18 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -59,6 +59,16 @@ person.last_name = "Galt"
|
|
59
59
|
person.last_name # Will be Galt
|
60
60
|
````
|
61
61
|
|
62
|
+
You can also pass an optional subject to to_object, and the properties will be added to that method.
|
63
|
+
````ruby
|
64
|
+
subject = ClassWithNoName.new
|
65
|
+
person = [:name].to_object subject
|
66
|
+
|
67
|
+
person.name = "John Galt"
|
68
|
+
person.name # Will be John Galt
|
69
|
+
````
|
70
|
+
|
71
|
+
|
62
72
|
### Safety Proc
|
63
73
|
|
64
74
|
This feature was written because I hate wrapping code in begin/rescue/end blocks. If I have a line of code and I don't particularly care if it fails, I have to wrap it in three more lines of care to stop exceptions.
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Array
|
2
2
|
|
3
|
-
def to_object
|
4
|
-
|
5
|
-
self.each { |item| add_reader_for(
|
6
|
-
|
3
|
+
def to_object(subject = nil)
|
4
|
+
subject = Object.new if subject.nil?
|
5
|
+
self.each { |item| add_reader_for(subject, item, nil) }
|
6
|
+
subject
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_objects(&blk)
|
data/lib/subtle/version.rb
CHANGED
@@ -37,5 +37,23 @@ describe "array to object" do
|
|
37
37
|
@result.respond_to?(:last_name=).must_equal true
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
describe "passing an object as a parameter" do
|
42
|
+
before do
|
43
|
+
@object = Object.new
|
44
|
+
@result = [:first_name, :last_name].to_object(@object)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return the same object passed to it" do
|
48
|
+
@result.must_be_same_as @object
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should add the properties in the array" do
|
52
|
+
@result.respond_to?(:first_name).must_equal true
|
53
|
+
@result.respond_to?(:first_name=).must_equal true
|
54
|
+
@result.respond_to?(:last_name).must_equal true
|
55
|
+
@result.respond_to?(:last_name=).must_equal true
|
56
|
+
end
|
57
|
+
end
|
40
58
|
|
41
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subtle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
segments:
|
107
107
|
- 0
|
108
|
-
hash:
|
108
|
+
hash: 3253476419710169719
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
none: false
|
111
111
|
requirements:
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash:
|
117
|
+
hash: 3253476419710169719
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
120
|
rubygems_version: 1.8.24
|