Skip to content

Instantly share code, notes, and snippets.

@mculp
Created June 7, 2012 04:46
Show Gist options
  • Select an option

  • Save mculp/2886627 to your computer and use it in GitHub Desktop.

Select an option

Save mculp/2886627 to your computer and use it in GitHub Desktop.
# so, we had a bug from a line of code doing this:
something_that_may_be_symbol_or_str.to_s +"something"
# => undefined method `+@' for "something":String
# TIL:
Derp = Class.new { def +@; puts 'WAT'; end }
# => Derp
+Derp.new
# => WAT
# but what is really weird is:
derp = 'hi'
# => "hi"
derp +'hi'
# => "hihi"
derp.to_s +'hi'
# => NoMethodError: undefined method `+@' for "hi":String
# haha, YES!
class MyNumber; @@number = 0; def +@; @@number += 1; end; end
number = MyNumber.new
# => #<MyNumber:0x000001008fb460>
++number
# => 1
++number
# => 2
++number
# => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment