Skip to content

Instantly share code, notes, and snippets.

@unixsuperhero
Created September 18, 2017 20:09
Show Gist options
  • Save unixsuperhero/654c3c0733e6ae232684968a75064eea to your computer and use it in GitHub Desktop.
Save unixsuperhero/654c3c0733e6ae232684968a75064eea to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module A
def self.included(base)
base.include InMethods
end
module InMethods
def mem
@mem ||= []
end
def add(n)
mem += n
end
end
end
class Help
include A
end
h = Help.new
h.add(1)
puts(mem: h.mem)
__END__
error-included-modules-accessing-eachother-errors.rb:14:in `add': undefined method `+' for nil:NilClass (NoMethodError)
from error-included-modules-accessing-eachother-errors.rb:24:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment