Created
October 14, 2020 06:36
-
-
Save ftiasch/6da1ef60acc17765b0aec3a7a552618b to your computer and use it in GitHub Desktop.
demonstrate the danger extending Ruby code objects with custom data members
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
class MyString < String | |
attr_reader :flag | |
def initialize(s, f) | |
super s | |
@flag = f | |
end | |
end | |
s1 = MyString.new ' misa', :misa | |
s2 = s1.lstrip | |
p [s1.flag, s2.flag] | |
s1.lstrip! | |
p s1.flag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment