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 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
- [![Build Status](https://travis-ci.org/colinyoung/ruby-with.png?branch=master)](undefined)
4
+ [![Build Status](https://travis-ci.org/colinyoung/ruby-with.png?branch=master)](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
  ![](http://i.imgur.com/0FIK5.png)
43
43
 
44
- To use, just call `with`:
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?):
@@ -18,8 +18,8 @@ module With
18
18
  context.instance_exec(self, &block)
19
19
 
20
20
  class << context
21
- remove_method :set
22
- remove_method :<=
21
+ remove_method :set if method_defined? :set
22
+ remove_method :<= if method_defined? :<=
23
23
  end
24
24
  end
25
25
 
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module With
3
- VERSION = "0.2"
3
+ VERSION = "0.3"
4
4
  end
5
5
  end
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.2'
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-01-15 00:00:00.000000000 Z
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest