Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Created June 30, 2011 19:08
Show Gist options
  • Save pcarrier/1056949 to your computer and use it in GitHub Desktop.
Save pcarrier/1056949 to your computer and use it in GitHub Desktop.
Run this in Ruby and enjoy.
def easier_life
nilmm = NilClass.instance_method(:method_missing)
NilClass.send :define_method, :method_missing, lambda {|*whatev|}
yield
NilClass.send :define_method, :method_missing, nilmm
end
def broken_code
[:only_item][10].oops.thats.very.wrong
[:only_item][10].oops.thats.very.wrong :with, :arguments
puts "whatever, I'm always happy"
end
easier_life do
broken_code
end
puts 'What happens without my hack? The answer after <enter>...'
$stdin.gets
broken_code
@Daenyth
Copy link

Daenyth commented Jul 1, 2011

-:3:in `block in easier_life': wrong number of arguments (1 for 0) (ArgumentError)
    from -:9:in `broken_code'
    from -:14:in `block in <main>'
    from -:4:in `easier_life'
    from -:13:in `<main>'

@pcarrier
Copy link
Author

pcarrier commented Jul 2, 2011

Oh you're right, I reproduced that with ruby 1.9.

Doing a new revision that works with 1.8 and 1.9.

@pcarrier
Copy link
Author

pcarrier commented Jul 2, 2011

... and here you go.

Thanks for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment