method-args 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/README.markdown +3 -3
- data/Rakefile +1 -0
- data/lib/method_args.rb +6 -6
- data/lib/method_args/version.rb +1 -1
- data/test/fixtures/3.rb +4 -0
- data/test/test_block.rb +9 -0
- metadata +8 -4
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
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
|
-
|
29
|
+
method-args!
|
30
30
|
minitest
|
31
31
|
phocus
|
32
32
|
rake
|
data/README.markdown
CHANGED
@@ -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
data/lib/method_args.rb
CHANGED
@@ -145,10 +145,10 @@ module MethodArgs
|
|
145
145
|
t = exp.shift
|
146
146
|
case t
|
147
147
|
when Symbol
|
148
|
-
arg_list <<
|
149
|
-
|
150
|
-
|
151
|
-
|
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)
|
data/lib/method_args/version.rb
CHANGED
data/test/fixtures/3.rb
ADDED
data/test/test_block.rb
ADDED
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
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
|