method-args 0.0.3 → 0.0.4

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- method_args (0.0.1)
4
+ method-args (0.0.3)
5
5
  ruby2ruby (~> 1.2.4)
6
6
  ruby_parser (~> 2.0)
7
7
  sexp_processor (~> 3.0.4)
@@ -26,7 +26,7 @@ PLATFORMS
26
26
  DEPENDENCIES
27
27
  bundler (~> 1.0.0)
28
28
  callsite (~> 0.0.4)
29
- method_args!
29
+ method-args!
30
30
  minitest
31
31
  phocus
32
32
  rake
@@ -15,7 +15,7 @@ Pretend you have a file `your_ruby_file.rb`:
15
15
  @default_value = 'hello'
16
16
  end
17
17
 
18
- def something(one, two = 'two', three = @default_value)
18
+ def something(one, two = 'two', three = @default_value, *more, &block)
19
19
  end
20
20
  end
21
21
 
@@ -27,10 +27,10 @@ To look at the arguments to something, do the following.
27
27
  This will return an `ArgList` object. You can then look at the names & types.
28
28
 
29
29
  MyClass.instance_method(:something).args.names
30
- # => [:one, :two, :three]
30
+ # => [:one, :two, :three, :more, :block]
31
31
 
32
32
  MyClass.instance_method(:something).args.types
33
- # => [:required, :optional, :splat]
33
+ # => [:required, :optional, :optional, :splat, :block]
34
34
 
35
35
  If you want to get the value of a default argument, you'll need a context in which to evaluate it, namely,
36
36
  an instance of the class from which the method derives.
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'bundler'
3
3
 
4
4
  desc "Run tests"
5
5
  task :test do
6
+ $: << '.'
6
7
  $: << 'lib'
7
8
  require 'method_args'
8
9
  require 'test/helper'
@@ -145,10 +145,10 @@ module MethodArgs
145
145
  t = exp.shift
146
146
  case t
147
147
  when Symbol
148
- arg_list << if t.to_s[0] == ?*
149
- ArgList::Arg.new(t.to_s[1, t.to_s.size].to_sym, :splat)
150
- else
151
- ArgList::Arg.new(t, :required)
148
+ arg_list << case t.to_s[0]
149
+ when ?* then ArgList::Arg.new(t.to_s[1, t.to_s.size].to_sym, :splat)
150
+ when ?& then ArgList::Arg.new(t.to_s[1, t.to_s.size].to_sym, :block)
151
+ else ArgList::Arg.new(t, :required)
152
152
  end
153
153
  when Sexp
154
154
  case t.shift
@@ -166,7 +166,7 @@ module MethodArgs
166
166
  end
167
167
 
168
168
  def add_methods
169
- unless current_class.const_defined?(:ArgList)
169
+ unless current_class.method(:const_defined?).arity == 2 ? current_class.const_defined?(:ArgList, false) : current_class.const_defined?(:ArgList)
170
170
  current_class.send(:const_set, :ArgList, @method_maps[current_classname])
171
171
  current_class.module_eval(<<-HERE_DOC, __FILE__, __LINE__)
172
172
  alias_method :__method__, :method
@@ -189,7 +189,7 @@ module MethodArgs
189
189
  def self.instance_arg_list(method_name)
190
190
  method = __instance_method__(method_name)
191
191
  if method.owner == self
192
- ArgList[method_name]
192
+ ArgList[method_name] or raise('i don\\'t know this method ' + method_name.inspect)
193
193
  elsif method.owner.respond_to?(:instance_arg_list)
194
194
  method.owner.instance_arg_list(method_name)
195
195
  # elsif method.respond_to?(:source_location)
@@ -1,3 +1,3 @@
1
1
  module MethodArgs
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,4 @@
1
+ class MyClass
2
+ def block(arg, arg2 = 1, *splat, &blk)
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ class TestBlock < MiniTest::Unit::TestCase
2
+ def setup
3
+ MethodArgs.load(~'fixtures/3')
4
+ end
5
+
6
+ def test_block
7
+ assert_equal [:required, :optional, :splat, :block], MyClass.instance_method(:block).args.types
8
+ end
9
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method-args
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-03 00:00:00 -08:00
18
+ date: 2011-01-04 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -159,7 +159,9 @@ files:
159
159
  - method_args.gemspec
160
160
  - test/fixtures/1.rb
161
161
  - test/fixtures/2.rb
162
+ - test/fixtures/3.rb
162
163
  - test/helper.rb
164
+ - test/test_block.rb
163
165
  - test/test_bound_method.rb
164
166
  - test/test_simple.rb
165
167
  - test/test_subclass.rb
@@ -200,7 +202,9 @@ summary: Get back more detailed information about the arguments for a method
200
202
  test_files:
201
203
  - test/fixtures/1.rb
202
204
  - test/fixtures/2.rb
205
+ - test/fixtures/3.rb
203
206
  - test/helper.rb
207
+ - test/test_block.rb
204
208
  - test/test_bound_method.rb
205
209
  - test/test_simple.rb
206
210
  - test/test_subclass.rb