sawa
sawa

Reputation: 168071

irb terminates with no method error

When I input the following lines in irb, the irb terminates.

$ irb
irb(main):001:0> def !; end
=> :!
irb(main):002:0> !
/usr/local/lib/ruby/2.1.0/irb/input-method.rb:153:in `gets': private method `!' called for false:FalseClass (NoMethodError)
...
$

Leaving aside the question of whether defining or calling a method named ! is valid or not, I suppose irb should not quit even when an error is raised. Is this a bug? Do you know what causes this?

Upvotes: 2

Views: 125

Answers (1)

Linuxios
Linuxios

Reputation: 35783

With this code in a file:

def !;
  puts "Hi"
end

send(:!)

!();

Ruby (1.9.3) gives this:

Hi
testexclaim.rb:7:in `<main>': private method `!' called for nil:NilClass (NoMethodError)

In my 1.9.3 IRB, it seems to be interpreting the ! as the not operator, even with parenthesis.

It seems to me that because send works, this is more of a parsing bug than anything else that neither IRB nor Ruby can handle.

Upvotes: 2

Related Questions