ruby-with 0.2 → 0.3
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/README.md +22 -3
- data/lib/ruby-with.rb +2 -2
- data/lib/ruby-with/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
## A `with` keyword for Ruby
|
2
2
|
#### (That has nothing to do with python's `with` keyword)
|
3
3
|
|
4
|
-
[](
|
4
|
+
[](https://travis-ci.org/colinyoung/ruby-with)
|
5
5
|
|
6
6
|
`with` lets you seamlessly make any object the current context.
|
7
7
|
|
@@ -41,9 +41,9 @@ end
|
|
41
41
|
|
42
42
|

|
43
43
|
|
44
|
-
To
|
44
|
+
To access object variables without typing `self`, just call `with` on that object:
|
45
45
|
|
46
|
-
```
|
46
|
+
```ruby
|
47
47
|
users.each do |user|
|
48
48
|
with user do
|
49
49
|
puts name
|
@@ -51,6 +51,25 @@ users.each do |user|
|
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
54
|
+
To SET the object's variables, use the usual `self.attribute = val` method, or one
|
55
|
+
of two provided methods that can make that far less annoying:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
with user do
|
59
|
+
set name: 'Leo'
|
60
|
+
puts name # => Leo
|
61
|
+
|
62
|
+
# OR
|
63
|
+
self <= { name: 'CJ' }
|
64
|
+
|
65
|
+
# Of course you can still do it the original way
|
66
|
+
# (which is exactly what the above two methods do behind-the-scenes)
|
67
|
+
self.name = "Jed"
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
### Use it!
|
72
|
+
|
54
73
|
You have two options to use ruby-with in your app:
|
55
74
|
|
56
75
|
1. Keyword-level integration (make `with` available everywhere, because why not?):
|
data/lib/ruby-with.rb
CHANGED
data/lib/ruby-with/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|