Created
June 7, 2012 04:46
-
-
Save mculp/2886627 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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