Skip to content

Instantly share code, notes, and snippets.

@bwilkins
Last active November 24, 2015 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwilkins/be21cc3b5c62d698c150 to your computer and use it in GitHub Desktop.
Save bwilkins/be21cc3b5c62d698c150 to your computer and use it in GitHub Desktop.
$ ruby hoist_wtf.rb
hoist_wtf.rb:8:in `do_thing': undefined method `+' for nil:NilClass (NoMethodError)
from hoist_wtf.rb:13:in `<main>'
$
class FoobarDoesThings
def initialize(foo)
@foo=foo
end
def do_thing
foo
foo += 1
end
attr_reader :foo
end
FoobarDoesThings.new(1).foo
@parndt
Copy link

parndt commented Nov 24, 2015

$ irb
irb(main):001:0> class FoobarDoesThings
irb(main):002:1>   def initialize(foo)
irb(main):003:2>     @foo=foo
irb(main):004:2>   end
irb(main):005:1> 
irb(main):006:1*   def do_thing
irb(main):007:2>     foo
irb(main):008:2>     foo += 1
irb(main):009:2>   end
irb(main):010:1>   attr_reader :foo
irb(main):011:1> end
=> nil
irb(main):012:0> 
irb(main):013:0* FoobarDoesThings.new(1).foo
=> 1
$ cat foo.rb 
class FoobarDoesThings
  def initialize(foo)
    @foo=foo
  end

  def do_thing
    foo
    foo += 1
  end
  attr_reader :foo
end
$ ruby foo.rb

^ produces nothing, not an exception either.

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