instance_call 0.0.2 → 1.0.0

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
@@ -30,11 +30,13 @@ require 'instance_call'
30
30
  array.instance_call(:push, string) # [1, 2, 3, "abc"]
31
31
  array.instance_call(lambda { [self, last]}) # [[1, 2, 3, "abc"], "abc"] - Note that self is not main
32
32
  array.instance_call() {|| self } # [1, 2, 3, "abc"]
33
+
34
+ array.instance_call(:'last.concat', 'd') # [1, 2, 3, "abcd"]
33
35
  ```
34
36
 
35
37
  ```ruby
36
38
  unbound_method = Array.instance_method(:pop)
37
- array.instance_call(unbound_method) # "abc"
39
+ array.instance_call(unbound_method) # "abcd"
38
40
  ```
39
41
 
40
42
  ```ruby
@@ -43,4 +45,4 @@ require 'instance_call'
43
45
  ```
44
46
 
45
47
 
46
- More examples can be seen in Rspec tests: https://github.com/tione/instance_call/tree/master/spec
48
+ More examples can be seen in Rspec (tests)[https://github.com/tione/instance_call/blob/master/spec/lib/instance_call/core_ext/object_spec.rb]
@@ -1,10 +1,17 @@
1
1
  class Object
2
-
2
+
3
3
  def instance_call(m=nil, *args, &block)
4
4
  m ||= block
5
5
  case m
6
6
  when Symbol
7
- send(m, *args, &block)
7
+ e = "#{m}".split('.')
8
+ l = e.pop
9
+ if e.empty?
10
+ send(l, *args, &block)
11
+ else
12
+ r = e.inject(self) {|object, method| object.send(method) }
13
+ r.send(l, *args, &block)
14
+ end
8
15
  when Proc
9
16
  instance_exec(*args, &m)
10
17
  when UnboundMethod
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instance_call
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
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: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard