File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -362,18 +362,19 @@ class SuperAmpersand
362
362
class RespondViaMissing
363
363
def respond_to_missing? ( method , priv = false )
364
364
case method
365
- when :handled_publicly
366
- true
367
- when :handled_privately
368
- priv
369
- when :not_handled
370
- false
371
- else
372
- raise "Typo in method name"
365
+ when :handled_publicly
366
+ true
367
+ when :handled_privately
368
+ priv
369
+ when :not_handled
370
+ false
371
+ else
372
+ raise "Typo in method name: #{ method . inspect } "
373
373
end
374
374
end
375
375
376
376
def method_missing ( method , *args )
377
+ raise "the method name should be a Symbol" unless Symbol === method
377
378
"Done #{ method } (#{ args } )"
378
379
end
379
380
end
Original file line number Diff line number Diff line change @@ -15,12 +15,18 @@ class KernelSpecs::Foo; def self.bar; 'class done'; end; end
15
15
m . call . should == 'class done'
16
16
end
17
17
18
- it "returns a method object if we repond_to_missing? method" do
18
+ it "returns a method object if respond_to_missing?( method) is true " do
19
19
m = KernelSpecs ::RespondViaMissing . new . send ( @method , :handled_publicly )
20
20
m . should be_an_instance_of Method
21
21
m . call ( 42 ) . should == "Done handled_publicly([42])"
22
22
end
23
23
24
+ it "the returned method object if respond_to_missing?(method) calls #method_missing with a Symbol name" do
25
+ m = KernelSpecs ::RespondViaMissing . new . send ( @method , "handled_publicly" )
26
+ m . should be_an_instance_of Method
27
+ m . call ( 42 ) . should == "Done handled_publicly([42])"
28
+ end
29
+
24
30
it "raises a NameError for an invalid method name" do
25
31
class KernelSpecs ::Foo ; def bar ; 'done' ; end ; end
26
32
-> {
You can’t perform that action at this time.
0 commit comments